From 249583899c0c97bfd88fd06214fb1f6bae9f1add Mon Sep 17 00:00:00 2001
From: Roman Tsisyk <roman@tsisyk.com>
Date: Tue, 15 Sep 2015 13:32:51 +0300
Subject: [PATCH] Fix #574: crash on exit after change of replication source

---
 src/coeio.cc                |  7 ++++---
 test/app/cfg.test.lua       |  7 +++++++
 test/box/bsdsocket.result   | 13 +++++++++++++
 test/box/bsdsocket.test.lua | 10 ++++++++++
 4 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/coeio.cc b/src/coeio.cc
index a8efa0bb60..5d3c8c82a0 100644
--- a/src/coeio.cc
+++ b/src/coeio.cc
@@ -170,10 +170,11 @@ coio_task(struct coio_task *task, coio_task_cb func,
 	task->complete = 0;
 
 	eio_submit(&task->base);
-
-	if (fiber_yield_timeout(timeout) && !task->complete) {
-		/* timed out. */
+	fiber_yield_timeout(timeout);
+	if (!task->complete) {
+		/* timed out or cancelled. */
 		task->fiber = NULL;
+		fiber_testcancel();
 		tnt_raise(TimedOut);
 	}
 
diff --git a/test/app/cfg.test.lua b/test/app/cfg.test.lua
index a5c2a80d1c..6a549dca5d 100755
--- a/test/app/cfg.test.lua
+++ b/test/app/cfg.test.lua
@@ -80,6 +80,13 @@ test:is(box.cfg.too_long_threshold, 0.5, "too_long_threshold default value")
 box.cfg{too_long_threshold=0.1}
 test:is(box.cfg.too_long_threshold , 0.1, "too_long_threshold new value")
 
+--------------------------------------------------------------------------------
+-- gh-537: segmentation fault with replication_source
+--------------------------------------------------------------------------------
+
+box.cfg{replication_source = 'guest:password@localhost:0'}
+box.cfg{replication_source = ""}
+
 local tarantool_bin = arg[-1]
 local PANIC = 256
 function run_script(code)
diff --git a/test/box/bsdsocket.result b/test/box/bsdsocket.result
index 763617fe2a..ca574d3332 100644
--- a/test/box/bsdsocket.result
+++ b/test/box/bsdsocket.result
@@ -1526,3 +1526,16 @@ socket.getaddrinfo('host', 'port', { flags = 'WRONG' }) == nil and errno() == er
 ---
 - true
 ...
+-- gh-574: check that fiber with getaddrinfo can be safely cancelled
+--# setopt delimiter ';'
+f = fiber.create(function()
+    while true do
+        local result = socket.getaddrinfo('localhost', '80')
+    end
+end);
+---
+...
+--# setopt delimiter ''
+f:cancel()
+---
+...
diff --git a/test/box/bsdsocket.test.lua b/test/box/bsdsocket.test.lua
index 0a8da452f2..871e04785c 100644
--- a/test/box/bsdsocket.test.lua
+++ b/test/box/bsdsocket.test.lua
@@ -523,3 +523,13 @@ socket.getaddrinfo('host', 'port', { type = 'WRONG' }) == nil and errno() == err
 socket.getaddrinfo('host', 'port', { family = 'WRONG' }) == nil and errno() == errno.EINVAL
 socket.getaddrinfo('host', 'port', { protocol = 'WRONG' }) == nil and errno() == errno.EINVAL
 socket.getaddrinfo('host', 'port', { flags = 'WRONG' }) == nil and errno() == errno.EINVAL
+
+-- gh-574: check that fiber with getaddrinfo can be safely cancelled
+--# setopt delimiter ';'
+f = fiber.create(function()
+    while true do
+        local result = socket.getaddrinfo('localhost', '80')
+    end
+end);
+--# setopt delimiter ''
+f:cancel()
-- 
GitLab