From f755748f72ea2370e25c23220a4ea7d1f1c515c1 Mon Sep 17 00:00:00 2001
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Date: Thu, 29 Nov 2018 22:22:04 +0300
Subject: [PATCH] coio: fix double close of a file descriptor

coio_service_on_accept is called by evio by an
on_accept pointer. If evio obtains not zero from
on_accept pointer, it closes accepted socket. But
coio_service_on_accept closes it too, when fiber_new
fails. It is double close.

Note that the bug existed even when on_accept was able
to throw.
---
 src/coio.cc | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/coio.cc b/src/coio.cc
index 46333e01a6..7bd73a86e9 100644
--- a/src/coio.cc
+++ b/src/coio.cc
@@ -596,9 +596,6 @@ coio_service_on_accept(struct evio_service *evio_service,
 {
 	struct coio_service *service = (struct coio_service *)
 			evio_service->on_accept_param;
-	struct ev_io coio;
-
-	coio_create(&coio, fd);
 
 	/* Set connection name. */
 	char fiber_name[SERVICE_NAME_MAXLEN];
@@ -610,9 +607,10 @@ coio_service_on_accept(struct evio_service *evio_service,
 	if (f == NULL) {
 		diag_log();
 		say_error("can't create a handler fiber, dropping client connection");
-		evio_close(loop(), &coio);
 		return -1;
 	}
+	struct ev_io coio;
+	coio_create(&coio, fd);
 	/*
 	 * The coio is passed into the created fiber, reset the
 	 * libev callback param to point at it.
-- 
GitLab