[PATCH 1/1] netbox: discard all requests on a connection close

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sun Aug 19 16:35:22 MSK 2018


Their responses are unreachable now since the socket is closed.
The bug was introduced by me during big netbox refactoring and
removal of requests retries here: 62ba7ba762. Such requests
evidently can be discarded immediately.

Closes #3629
---
https://github.com/tarantool/tarantool/tree/gerold103/gh-3629-netbox-leaks-again
https://github.com/tarantool/tarantool/issues/3629

 src/box/lua/net_box.lua   |  3 ++-
 test/box/net.box.result   | 43 +++++++++++++++++++++++++++++++++++++++++--
 test/box/net.box.test.lua | 16 ++++++++++++++++
 3 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
index f5176ae13..fd6ebf9de 100644
--- a/src/box/lua/net_box.lua
+++ b/src/box/lua/net_box.lua
@@ -393,7 +393,8 @@ local function create_transport(host, port, user, password, callback,
         last_error = new_error
         callback('state_changed', new_state, new_errno, new_error)
         state_cond:broadcast()
-        if state == 'error' or state == 'error_reconnect' then
+        if state == 'error' or state == 'error_reconnect' or
+           state == 'closed' then
             for _, request in pairs(requests) do
                 request.id = nil
                 request.errno = new_errno
diff --git a/test/box/net.box.result b/test/box/net.box.result
index 37ac54658..4c4bcfafe 100644
--- a/test/box/net.box.result
+++ b/test/box/net.box.result
@@ -2942,12 +2942,12 @@ c:close()
 future2:wait_result(100)
 ---
 - null
-- Connection is not established
+- Connection closed
 ...
 future2:result()
 ---
 - null
-- Connection is not established
+- Connection closed
 ...
 future2:discard()
 ---
@@ -3122,6 +3122,45 @@ test_run:grep_log('default', 'too big packet size in the header') ~= nil
 ---
 - true
 ...
+--
+-- gh-3629: netbox leaks when a connection is closed deliberately
+-- and it has non-finished requests.
+--
+ready = false
+---
+...
+ok = nil
+---
+...
+err = nil
+---
+...
+c = net:connect(box.cfg.listen)
+---
+...
+function do_long() while not ready do fiber.sleep(0.01) end end
+---
+...
+f = fiber.create(function() ok, err = pcall(c.call, c, 'do_long') end)
+---
+...
+while f:status() ~= 'suspended' do fiber.sleep(0.01) end
+---
+...
+c:close()
+---
+...
+ready = true
+---
+...
+while not err do fiber.sleep(0.01) end
+---
+...
+ok, err
+---
+- false
+- Connection closed
+...
 box.schema.user.revoke('guest', 'read,write,execute', 'universe')
 ---
 ...
diff --git a/test/box/net.box.test.lua b/test/box/net.box.test.lua
index 56b656cc5..9a5e0a068 100644
--- a/test/box/net.box.test.lua
+++ b/test/box/net.box.test.lua
@@ -1263,4 +1263,20 @@ c._transport.perform_request(nil, nil, 'inject', nil, nil, data)
 c:close()
 test_run:grep_log('default', 'too big packet size in the header') ~= nil
 
+--
+-- gh-3629: netbox leaks when a connection is closed deliberately
+-- and it has non-finished requests.
+--
+ready = false
+ok = nil
+err = nil
+c = net:connect(box.cfg.listen)
+function do_long() while not ready do fiber.sleep(0.01) end end
+f = fiber.create(function() ok, err = pcall(c.call, c, 'do_long') end)
+while f:status() ~= 'suspended' do fiber.sleep(0.01) end
+c:close()
+ready = true
+while not err do fiber.sleep(0.01) end
+ok, err
+
 box.schema.user.revoke('guest', 'read,write,execute', 'universe')
-- 
2.15.2 (Apple Git-101.1)




More information about the Tarantool-patches mailing list