From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 4A9A76E225; Fri, 23 Jul 2021 14:08:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4A9A76E225 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1627038484; bh=gNXbXoWaYzQONpHZIQSQMz72lygVaj8sCO87e4Iebyk=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=P0Ux0EdACTr6ZjTxsSXF5TaxP9mNjixeA9zx+HfxzQFBkTgDni0pjI0ljvuAByFIs 8qHWygOB2aRC54+Ncovm5LLtIY8G1OlIjDrGaYST/PpS/CEak0LnEDQFEP6+EayRge MSmOTcvWn+pDibTGdL/FHrRWfF3zSz0qBOCPPmII= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id C8F396EC55 for ; Fri, 23 Jul 2021 14:07:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C8F396EC55 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1m6t1f-0004dl-9y; Fri, 23 Jul 2021 14:07:31 +0300 To: tarantool-patches@dev.tarantool.org Date: Fri, 23 Jul 2021 14:07:11 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-174C08C4: 5188C02AEC42908C481ED7ADC579193296BBA28369E3F2D2713F3D5F7D406D31BCF678C7329BA986 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C3FDAB68B812060C77E621B90589399EB5182A05F538085040E6D6B52C12C6FF141F26698CA3386FE6104D8B707835E5BEEED5172667482B8B X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F095E3787A950C88EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637B6B039AA0E19584A8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D860A946F6D24CF5F44ABED10D1C00514D117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3A703B70628EAD7BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6753C3A5E0A5AB5B7089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 8BD88D57C5CADBC8B2710865C3867510A0B4543D0F65078DA3B1A56EE2B804F6B226C914C996894645FD9D8A29397D6EFF55FE49A3C2BFCFC8C84E951CD0BE2F296C473AB1E14218EA052B563B0B06C67866D6147AF826D860A946F6D24CF5F44ABED10D1C00514DF972CCD2F8FE1EF1CFC4036BBF6A4EA9C43DFD2748B764B0C5C67F257BE79497DA5036C42366A8A0C4228FA71A778DD3 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D342B8615F5CFAD9D0298107DBF4ABEA55FEDA4B32E1E141E975C9A9425CC869B5B514DFFA492194E0F1D7E09C32AA3244C9D57DDA52332303816766CF6A9EF2ED1D08D48398F32B4A6729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXiEX0g4jkpDtcL5LiTmgAhB X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D9405F6FD1092D34A0951660DBA1D42C0274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 01/20] net.box: fix console connection breakage when request is discarded X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladimir Davydov via Tarantool-patches Reply-To: Vladimir Davydov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" If a timed-out console request is collected by the garbage collector before the response is processed, the connection will stop serving new requests. This happens because of the erroneous 'return' statement in console_sm. Fix it and add a test. --- src/box/lua/net_box.c | 1 + src/box/lua/net_box.lua | 20 +++--- src/lib/core/errinj.h | 1 + test/box/errinj.result | 1 + .../net.box_discard_console_request.result | 62 +++++++++++++++++++ .../net.box_discard_console_request.test.lua | 19 ++++++ test/box/suite.ini | 2 +- 7 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 test/box/net.box_discard_console_request.result create mode 100644 test/box/net.box_discard_console_request.test.lua diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index 3f43872ca2e4..ed1df4a189d2 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -542,6 +542,7 @@ check_limit: } ev_tstamp deadline = ev_monotonic_now(loop()) + timeout; + ERROR_INJECT_YIELD(ERRINJ_NETBOX_IO_DELAY); revents = coio_wait(fd, EV_READ | (ibuf_used(send_buf) != 0 ? EV_WRITE : 0), timeout); luaL_testcancel(L); diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 3878abf21914..5fd8b96b079d 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -671,6 +671,17 @@ local function create_transport(host, port, user, password, callback, request.cond:broadcast() end + local function dispatch_response_console(rid, response) + local request = requests[rid] + if request == nil then -- nobody is waiting for the response + return + end + request.id = nil + requests[rid] = nil + request.response = response + request.cond:broadcast() + end + local function new_request_id() local id = next_request_id; next_request_id = next_id(id) @@ -771,14 +782,7 @@ local function create_transport(host, port, user, password, callback, if err then return error_sm(err, response) else - local request = requests[rid] - if request == nil then -- nobody is waiting for the response - return - end - request.id = nil - requests[rid] = nil - request.response = response - request.cond:broadcast() + dispatch_response_console(rid, response) return console_sm(next_id(rid)) end end diff --git a/src/lib/core/errinj.h b/src/lib/core/errinj.h index e492428071d9..3fe4c7c22cc8 100644 --- a/src/lib/core/errinj.h +++ b/src/lib/core/errinj.h @@ -154,6 +154,7 @@ struct errinj { _(ERRINJ_IPROTO_SINGLE_THREAD_STAT, ERRINJ_INT, {.iparam = -1}) \ _(ERRINJ_IPROTO_WRITE_ERROR_DELAY, ERRINJ_BOOL, {.bparam = false})\ _(ERRINJ_APPLIER_READ_TX_ROW_DELAY, ERRINJ_BOOL, {.bparam = false})\ + _(ERRINJ_NETBOX_IO_DELAY, ERRINJ_BOOL, {.bparam = false}) \ ENUM0(errinj_id, ERRINJ_LIST); extern struct errinj errinjs[]; diff --git a/test/box/errinj.result b/test/box/errinj.result index 44f86a54e7eb..adb682ac3a5c 100644 --- a/test/box/errinj.result +++ b/test/box/errinj.result @@ -63,6 +63,7 @@ evals - ERRINJ_IPROTO_WRITE_ERROR_DELAY: false - ERRINJ_LOG_ROTATE: false - ERRINJ_MEMTX_DELAY_GC: false + - ERRINJ_NETBOX_IO_DELAY: false - ERRINJ_PORT_DUMP: false - ERRINJ_RELAY_BREAK_LSN: -1 - ERRINJ_RELAY_EXIT_DELAY: 0 diff --git a/test/box/net.box_discard_console_request.result b/test/box/net.box_discard_console_request.result new file mode 100644 index 000000000000..e8da50a2f648 --- /dev/null +++ b/test/box/net.box_discard_console_request.result @@ -0,0 +1,62 @@ +-- test-run result file version 2 +test_run = require('test_run').new() + | --- + | ... +fio = require('fio') + | --- + | ... +net = require('net.box') + | --- + | ... +console = require('console') + | --- + | ... +errinj = box.error.injection + | --- + | ... + +console_sock_path = fio.pathjoin(fio.cwd(), 'console.sock') + | --- + | ... +_ = fio.unlink(console_sock_path) + | --- + | ... +s = console.listen(console_sock_path) + | --- + | ... +c = net.connect('unix/', console_sock_path, {console = true}) + | --- + | ... + +errinj.set('ERRINJ_NETBOX_IO_DELAY', true) + | --- + | - ok + | ... +c:eval('return', 0) -- timeout, but the request is still in flight + | --- + | - error: Timeout exceeded + | ... +collectgarbage('collect') -- force garbage collection of the request + | --- + | - 0 + | ... +errinj.set('ERRINJ_NETBOX_IO_DELAY', false) + | --- + | - ok + | ... +c:eval('return') -- ok + | --- + | - '--- + | + | ... + | + | ' + | ... + +c:close() + | --- + | ... +s:close() + | --- + | - true + | ... diff --git a/test/box/net.box_discard_console_request.test.lua b/test/box/net.box_discard_console_request.test.lua new file mode 100644 index 000000000000..52543e1d5649 --- /dev/null +++ b/test/box/net.box_discard_console_request.test.lua @@ -0,0 +1,19 @@ +test_run = require('test_run').new() +fio = require('fio') +net = require('net.box') +console = require('console') +errinj = box.error.injection + +console_sock_path = fio.pathjoin(fio.cwd(), 'console.sock') +_ = fio.unlink(console_sock_path) +s = console.listen(console_sock_path) +c = net.connect('unix/', console_sock_path, {console = true}) + +errinj.set('ERRINJ_NETBOX_IO_DELAY', true) +c:eval('return', 0) -- timeout, but the request is still in flight +collectgarbage('collect') -- force garbage collection of the request +errinj.set('ERRINJ_NETBOX_IO_DELAY', false) +c:eval('return') -- ok + +c:close() +s:close() diff --git a/test/box/suite.ini b/test/box/suite.ini index 5ac3979dbbf4..d9379cc0f28a 100644 --- a/test/box/suite.ini +++ b/test/box/suite.ini @@ -5,7 +5,7 @@ script = box.lua disabled = rtree_errinj.test.lua tuple_bench.test.lua long_run = huge_field_map_long.test.lua config = engine.cfg -release_disabled = errinj.test.lua errinj_index.test.lua rtree_errinj.test.lua upsert_errinj.test.lua iproto_stress.test.lua gh-4648-func-load-unload.test.lua gh-5645-several-iproto-threads.test.lua +release_disabled = errinj.test.lua errinj_index.test.lua rtree_errinj.test.lua upsert_errinj.test.lua iproto_stress.test.lua gh-4648-func-load-unload.test.lua gh-5645-several-iproto-threads.test.lua box/net.box_discard_console_request.test.lua lua_libs = lua/fifo.lua lua/utils.lua lua/bitset.lua lua/index_random_test.lua lua/push.lua lua/identifier.lua lua/txn_proxy.lua use_unix_sockets = True use_unix_sockets_iproto = True -- 2.25.1