forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net.box: fix
on_disconnect
inconsistency with documentation
According to the documentation [1]: > If the trigger function causes an error, the error is logged but otherwise is ignored. However, currently, the `on_disconnect` trigger behaves the same way as the `on_connect` trigger, i.e., the connection is terminated and its state changes to 'error'. Let's fix this inconsistency and log errors from the `on_disconnect` trigger, but otherwise ignore them. Closes tarantool#9677 Closes tarantool#9797 NO_DOC=<bugfix> 1. https://www.tarantool.io/en/doc/latest/reference/reference_lua/net_box/#lua-function.conn.on_disconnect
- Loading branch information
1 parent
40bd0eb
commit a0f4f00
Showing
6 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
changelogs/unreleased/gh-9677-netbox-on_disconnect-error-behaviour.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## bugfix/lua | ||
|
||
* Fixed an inconsistency between the documented `on_disconnect` trigger behavior | ||
of `net.box` connections when an error is thrown and the actual behavior | ||
(gh-9717). |
5 changes: 5 additions & 0 deletions
5
changelogs/unreleased/gh-9797-netbox-on_disconnect-error-hangs-server.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## bugfix/lua | ||
|
||
* Fixed a bug in the `on_disconnect` trigger of `net.box` connections that | ||
caused Tarantool server to hang indefinitely when an error was thrown from the | ||
trigger (gh-9797). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/box-luatest/gh_9677_netbox_on_disconnect_error_behaviour_test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
|
||
local g = t.group() | ||
|
||
g.before_all(function(cg) | ||
cg.server = server:new() | ||
cg.server:start() | ||
end) | ||
|
||
g.after_all(function(cg) | ||
cg.server:drop() | ||
end) | ||
|
||
-- Tests that the actual behaviour of the `on_disconnect` trigger when an error | ||
-- is thrown is consistent with its documented behaviour. | ||
g.test_on_disconnect_error_behaviour = function(cg) | ||
local trigger_err = '777' | ||
cg.server:exec(function(trigger_err) | ||
local net_box = require('net.box') | ||
|
||
local c = net_box.connect(box.cfg.listen) | ||
c:on_disconnect(function() | ||
error(trigger_err) | ||
end) | ||
local ok = pcall(function() c:close() end) | ||
t.assert(ok) | ||
t.assert(c:wait_state('closed', 10)) | ||
end, {trigger_err}) | ||
t.assert(cg.server:grep_log(trigger_err)) | ||
end |
32 changes: 32 additions & 0 deletions
32
test/box-luatest/gh_9797_netbox_on_disconnect_error_hangs_server_test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
local net_box = require('net.box') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
|
||
local g = t.group() | ||
|
||
g.before_all(function(cg) | ||
cg.server = server:new() | ||
cg.server:start() | ||
end) | ||
|
||
g.after_all(function(cg) | ||
cg.server:drop() | ||
end) | ||
|
||
-- Tests that throwing an error from the `on_disconnect` trigger does not hang | ||
-- the server indefinitely. | ||
g.test_on_disconnect_error_hangs_server = function(cg) | ||
local c = net_box.connect(cg.server.net_box_uri) | ||
c:on_disconnect(function() | ||
error(777) | ||
end) | ||
pcall(function() c:close() end) | ||
local log_file = cg.server:exec(function() | ||
box.ctl.set_on_shutdown_timeout(1) | ||
-- `grep_log` will not be able to retrieve it after we drop the server. | ||
return box.cfg.log | ||
end) | ||
cg.server:drop() | ||
t.assert_not(cg.server:grep_log('on_shutdown triggers failed', 1024, | ||
{filename = log_file})) | ||
end |