Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
Subject: [tarantool-patches] [PATCH 1/1] iproto: on input discard do nothing for closed con
Date: Mon, 14 May 2018 19:30:03 +0300	[thread overview]
Message-ID: <4f647e0638c766bb243b9f8a6c4289f1dbfc7c23.1526315331.git.v.shpilevoy@tarantool.org> (raw)

When a connection is closed, some of long-poll requests still may
by in TX thread with non-discarded input. If a connection is
closed, and then an input is discarded, then connection must not
try to read new data.

The bug was introduced here:
f4d66dae85a59f5ba667f405ad7b67649f3dec7b by me.

Closes #3400
---
Branch: https://github.com/tarantool/tarantool/tree/gh-3400-iproto-crash
Issue: https://github.com/tarantool/tarantool/issues/3400

 src/box/iproto.cc         |  5 ++++-
 test/box/net.box.result   | 29 +++++++++++++++++++++++++++++
 test/box/net.box.test.lua | 17 +++++++++++++++++
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/src/box/iproto.cc b/src/box/iproto.cc
index 1e6c615da..6624b8d73 100644
--- a/src/box/iproto.cc
+++ b/src/box/iproto.cc
@@ -1160,7 +1160,8 @@ net_discard_input(struct cmsg *m)
 	msg->p_ibuf->rpos += msg->len;
 	msg->len = 0;
 	con->long_poll_requests++;
-	if (! ev_is_active(&con->input) && rlist_empty(&con->in_stop_list))
+	if (evio_has_fd(&con->input) && !ev_is_active(&con->input) &&
+	    rlist_empty(&con->in_stop_list))
 		ev_feed_event(con->loop, &con->input, EV_READ);
 }
 
@@ -1669,6 +1670,8 @@ iproto_on_accept(struct evio_service * /* service */, int fd,
 	cpipe_push(&tx_pipe, &msg->base);
 	return;
 error_msg:
+	ev_io_stop(con->loop, &con->input);
+	ev_io_stop(con->loop, &con->output);
 	mempool_free(&iproto_connection_pool, con);
 error_conn:
 	close(fd);
diff --git a/test/box/net.box.result b/test/box/net.box.result
index 2e6be0e64..1674c27e1 100644
--- a/test/box/net.box.result
+++ b/test/box/net.box.result
@@ -3033,6 +3033,35 @@ box.space.test2:drop()
 box.space.test3:drop()
 ---
 ...
+--
+-- gh-3400: long-poll input discard must not touch event loop of
+-- a closed connection.
+--
+function long() fiber.yield() return 100 end
+---
+...
+c = net.connect(box.cfg.listen)
+---
+...
+c:ping()
+---
+- true
+...
+-- Create batch of two requests. First request is sent to TX
+-- thread, second one terminates connection. The preceeding
+-- request discards input, and this operation must not trigger
+-- new attempts to read any data - the connection is closed
+-- already.
+--
+f = fiber.create(c._transport.perform_request, nil, nil, 'call_17', 'long', {}) c._transport.perform_request(nil, nil, 'inject', '\x80')
+---
+...
+while f:status() ~= 'dead' do fiber.sleep(0.01) end
+---
+...
+c:close()
+---
+...
 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 cb9a3dc69..c34616aec 100644
--- a/test/box/net.box.test.lua
+++ b/test/box/net.box.test.lua
@@ -1209,4 +1209,21 @@ box.space.test1:drop()
 box.space.test2:drop()
 box.space.test3:drop()
 
+--
+-- gh-3400: long-poll input discard must not touch event loop of
+-- a closed connection.
+--
+function long() fiber.yield() return 100 end
+c = net.connect(box.cfg.listen)
+c:ping()
+-- Create batch of two requests. First request is sent to TX
+-- thread, second one terminates connection. The preceeding
+-- request discards input, and this operation must not trigger
+-- new attempts to read any data - the connection is closed
+-- already.
+--
+f = fiber.create(c._transport.perform_request, nil, nil, 'call_17', 'long', {}) c._transport.perform_request(nil, nil, 'inject', '\x80')
+while f:status() ~= 'dead' do fiber.sleep(0.01) end
+c:close()
+
 box.schema.user.revoke('guest', 'read,write,execute', 'universe')
-- 
2.15.1 (Apple Git-101)

                 reply	other threads:[~2018-05-14 16:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4f647e0638c766bb243b9f8a6c4289f1dbfc7c23.1526315331.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 1/1] iproto: on input discard do nothing for closed con' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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