Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v2] Don't throw an exception in a replication handler
@ 2018-08-27  6:43 Georgy Kirichenko
  2018-08-27  9:44 ` Vladimir Davydov
  0 siblings, 1 reply; 2+ messages in thread
From: Georgy Kirichenko @ 2018-08-27  6:43 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Georgy Kirichenko

It is an error to throw an error out of a cbus message handler because
it breaks cbus message delivery. In case of replication throwing an
error prevents iproto against replication socket closing.

Fixes 3642
---
Changes in v2:
  - Test fixes (setrlimit, formating)
  - Test result file included

https://github.com/tarantool/tarantool/issues/3642
https://github.com/tarantool/tarantool/tree/g.kirichenko/gh-3642-fix-replication-socket-leak

 src/box/iproto.cc              |  2 +-
 test/replication/misc.result   | 98 ++++++++++++++++++++++++++++++++++
 test/replication/misc.test.lua | 45 ++++++++++++++++
 3 files changed, 144 insertions(+), 1 deletion(-)

diff --git a/src/box/iproto.cc b/src/box/iproto.cc
index ab7b42169..984c6df44 100644
--- a/src/box/iproto.cc
+++ b/src/box/iproto.cc
@@ -1424,7 +1424,7 @@ tx_process_join_subscribe(struct cmsg *m)
 			unreachable();
 		}
 	} catch (SocketError *e) {
-		throw; /* don't write error response to prevent SIGPIPE */
+		return; /* don't write error response to prevent SIGPIPE */
 	} catch (Exception *e) {
 		iproto_write_error(con->input.fd, e, ::schema_version,
 				   msg->header.sync);
diff --git a/test/replication/misc.result b/test/replication/misc.result
index 76e7fd5ee..fecdb495c 100644
--- a/test/replication/misc.result
+++ b/test/replication/misc.result
@@ -229,6 +229,104 @@ test_run:cmd("switch default")
 test_run:drop_cluster(SERVERS)
 ---
 ...
+ffi = require('ffi')
+---
+...
+test_run:cmd("setopt delimiter ';;'")
+---
+- true
+...
+ffi.cdef([[
+typedef long rlim_t;
+struct rlimit {
+    rlim_t rlim_cur;  /* Soft limit */
+    rlim_t rlim_max;  /* Hard limit (ceiling for rlim_cur) */
+};
+int getrlimit(int resource, struct rlimit *rlim);
+int setrlimit(int resource, const struct rlimit *rlim);
+]]);;
+---
+...
+test_run:cmd("setopt delimiter ''");;
+---
+- true
+...
+rlim = ffi.new('struct rlimit')
+---
+...
+ffi.C.getrlimit(7 --[[RLIMIT_NOFILE]], rlim)
+---
+- 0
+...
+old_rlim = rlim.rlim_cur
+---
+...
+rlim.rlim_cur = 64
+---
+...
+ffi.C.setrlimit(7 --[[RLIMIT_NOFILE]], rlim)
+---
+- 0
+...
+test_run:cmd('create server sock with rpl_master=default, script="replication/replica.lua"')
+---
+- true
+...
+test_run:cmd(string.format('start server sock'))
+---
+- true
+...
+test_run:cmd('switch sock')
+---
+- true
+...
+test_run = require('test_run').new()
+---
+...
+fiber = require('fiber')
+---
+...
+test_run:cmd("setopt delimiter ';'")
+---
+- true
+...
+for i = 1, 64 do
+    local replication = box.cfg.replication
+    box.cfg{replication = {}}
+    box.cfg{replication = replication}
+    while box.info.replication[1].upstream.status ~= 'follow' do
+        fiber.sleep(0.0001)
+    end
+end;
+---
+...
+test_run:cmd("setopt delimiter ''");
+---
+- true
+...
+box.info.replication[1].upstream.status
+---
+- follow
+...
+test_run:cmd('switch default')
+---
+- true
+...
+rlim.rlim_cur = old_rlim
+---
+...
+ffi.C.setrlimit(7 --[[RLIMIT_NOFILE]], rlim)
+---
+- 0
+...
+test_run:cmd('stop server sock')
+---
+- true
+...
+test_run:cmd('cleanup server sock')
+---
+- true
+...
 box.schema.user.revoke('guest', 'replication')
 ---
 ...
diff --git a/test/replication/misc.test.lua b/test/replication/misc.test.lua
index c60adf5a5..e72ae7cda 100644
--- a/test/replication/misc.test.lua
+++ b/test/replication/misc.test.lua
@@ -90,6 +90,51 @@ box.space.space1:drop()
 test_run:cmd("switch default")
 test_run:drop_cluster(SERVERS)
 
+ffi = require('ffi')
+test_run:cmd("setopt delimiter ';;'")
+ffi.cdef([[
+typedef long rlim_t;
+struct rlimit {
+    rlim_t rlim_cur;  /* Soft limit */
+    rlim_t rlim_max;  /* Hard limit (ceiling for rlim_cur) */
+};
+int getrlimit(int resource, struct rlimit *rlim);
+int setrlimit(int resource, const struct rlimit *rlim);
+]]);;
+test_run:cmd("setopt delimiter ''");;
+
+rlim = ffi.new('struct rlimit')
+ffi.C.getrlimit(7 --[[RLIMIT_NOFILE]], rlim)
+old_rlim = rlim.rlim_cur
+rlim.rlim_cur = 64
+ffi.C.setrlimit(7 --[[RLIMIT_NOFILE]], rlim)
+
+test_run:cmd('create server sock with rpl_master=default, script="replication/replica.lua"')
+test_run:cmd(string.format('start server sock'))
+test_run:cmd('switch sock')
+test_run = require('test_run').new()
+fiber = require('fiber')
+test_run:cmd("setopt delimiter ';'")
+for i = 1, 64 do
+    local replication = box.cfg.replication
+    box.cfg{replication = {}}
+    box.cfg{replication = replication}
+    while box.info.replication[1].upstream.status ~= 'follow' do
+        fiber.sleep(0.0001)
+    end
+end;
+test_run:cmd("setopt delimiter ''");
+
+box.info.replication[1].upstream.status
+
+test_run:cmd('switch default')
+
+rlim.rlim_cur = old_rlim
+ffi.C.setrlimit(7 --[[RLIMIT_NOFILE]], rlim)
+
+test_run:cmd('stop server sock')
+test_run:cmd('cleanup server sock')
+
 box.schema.user.revoke('guest', 'replication')
 
 --
-- 
2.18.0

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

end of thread, other threads:[~2018-08-27  9:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-27  6:43 [tarantool-patches] [PATCH v2] Don't throw an exception in a replication handler Georgy Kirichenko
2018-08-27  9:44 ` Vladimir Davydov

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