Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH 1/1] netbox: discard all requests on a connection close
@ 2018-08-19 13:35 Vladislav Shpilevoy
  2018-08-20 16:57 ` Vladimir Davydov
  0 siblings, 1 reply; 2+ messages in thread
From: Vladislav Shpilevoy @ 2018-08-19 13:35 UTC (permalink / raw)
  To: tarantool-patches; +Cc: vdavydov.dev

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)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-20 16:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-19 13:35 [PATCH 1/1] netbox: discard all requests on a connection close Vladislav Shpilevoy
2018-08-20 16:57 ` Vladimir Davydov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox