Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com
Subject: [PATCH 4/4] session: kill a session of a closed connection
Date: Fri,  7 Dec 2018 18:46:35 +0300	[thread overview]
Message-ID: <52080b13da7f20e84138d551f4c65f46d0781907.1544197465.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1544197465.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1544197465.git.v.shpilevoy@tarantool.org>

Once a connection is closed, a long-running user
request can not learn about this occasion. Even
box.sesion.push() still works.

This patch makes such disconnected session dead. So
a user can determine if a connection is closed by
looking at session type == 'dead', or checking for
errors from box.session.push().

Closes #3859
---
 src/box/iproto.cc      |  9 +++++---
 test/box/push.result   | 50 ++++++++++++++++++++++++++++++++++++++++++
 test/box/push.test.lua | 22 +++++++++++++++++++
 3 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/src/box/iproto.cc b/src/box/iproto.cc
index 19ee67958..b6c2ab587 100644
--- a/src/box/iproto.cc
+++ b/src/box/iproto.cc
@@ -1225,9 +1225,12 @@ tx_process_disconnect(struct cmsg *m)
 {
 	struct iproto_connection *con =
 		container_of(m, struct iproto_connection, disconnect_msg);
-	if (con->session != NULL && !rlist_empty(&session_on_disconnect)) {
-		tx_fiber_init(con->session, 0);
-		session_run_on_disconnect_triggers(con->session);
+	if (con->session != NULL) {
+		session_kill(con->session);
+		if (! rlist_empty(&session_on_disconnect)) {
+			tx_fiber_init(con->session, 0);
+			session_run_on_disconnect_triggers(con->session);
+		}
 	}
 }
 
diff --git a/test/box/push.result b/test/box/push.result
index af730c1a7..d2f6a6803 100644
--- a/test/box/push.result
+++ b/test/box/push.result
@@ -497,6 +497,56 @@ box.schema.func.drop('do_pushes')
 s:drop()
 ---
 ...
+--
+-- gh-3859: box.session.push() succeeds even after the connection
+-- is closed.
+--
+chan_push = fiber.channel()
+---
+...
+chan_disconnected = fiber.channel()
+---
+...
+test_run:cmd("setopt delimiter ';'")
+---
+- true
+...
+function do_long_and_push()
+    box.session.on_disconnect(function() chan_disconnected:put(true) end)
+    chan_push:get()
+    ok, err = box.session.push(100)
+    chan_push:put(err)
+end;
+---
+...
+test_run:cmd("setopt delimiter ''");
+---
+- true
+...
+box.schema.func.create('do_long_and_push')
+---
+...
+box.schema.user.grant('guest', 'execute', 'function', 'do_long_and_push')
+---
+...
+f = fiber.create(function() c:call('do_long_and_push') end)
+---
+...
 c:close()
 ---
 ...
+chan_disconnected:get()
+---
+- true
+...
+chan_push:put(true)
+---
+- true
+...
+chan_push:get()
+---
+- Session 'dead' does not support push()
+...
+box.schema.func.drop('do_long_and_push')
+---
+...
diff --git a/test/box/push.test.lua b/test/box/push.test.lua
index 893cf0153..514c08b3e 100644
--- a/test/box/push.test.lua
+++ b/test/box/push.test.lua
@@ -237,4 +237,26 @@ keys
 box.schema.func.drop('do_push_and_duplicate')
 box.schema.func.drop('do_pushes')
 s:drop()
+
+--
+-- gh-3859: box.session.push() succeeds even after the connection
+-- is closed.
+--
+chan_push = fiber.channel()
+chan_disconnected = fiber.channel()
+test_run:cmd("setopt delimiter ';'")
+function do_long_and_push()
+    box.session.on_disconnect(function() chan_disconnected:put(true) end)
+    chan_push:get()
+    ok, err = box.session.push(100)
+    chan_push:put(err)
+end;
+test_run:cmd("setopt delimiter ''");
+box.schema.func.create('do_long_and_push')
+box.schema.user.grant('guest', 'execute', 'function', 'do_long_and_push')
+f = fiber.create(function() c:call('do_long_and_push') end)
 c:close()
+chan_disconnected:get()
+chan_push:put(true)
+chan_push:get()
+box.schema.func.drop('do_long_and_push')
-- 
2.17.2 (Apple Git-113)

  parent reply	other threads:[~2018-12-07 15:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-07 15:46 [PATCH 0/4] Outdate disconnected session Vladislav Shpilevoy
2018-12-07 15:46 ` [PATCH 1/4] iproto: rename disconnect cmsg to destroy Vladislav Shpilevoy
2018-12-07 17:36   ` [tarantool-patches] " Konstantin Osipov
2018-12-11 12:54     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-07 15:46 ` [PATCH 2/4] iproto: fire on_disconnect right after disconnect Vladislav Shpilevoy
2018-12-07 17:37   ` [tarantool-patches] " Konstantin Osipov
2018-12-11 12:55     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-07 15:46 ` [PATCH 3/4] session: introduce 'dead' type Vladislav Shpilevoy
2018-12-07 17:38   ` [tarantool-patches] " Konstantin Osipov
2018-12-07 20:40     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-07 22:21       ` Konstantin Osipov
2018-12-07 22:42         ` Vladislav Shpilevoy
2018-12-07 15:46 ` Vladislav Shpilevoy [this message]
2018-12-07 17:35 ` [tarantool-patches] [PATCH 0/4] Outdate disconnected session Konstantin Osipov
2018-12-11 16:12   ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-07 17:41 ` [tarantool-patches] " Konstantin Osipov
2018-12-11 16:13   ` [tarantool-patches] " Vladislav Shpilevoy

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=52080b13da7f20e84138d551f4c65f46d0781907.1544197465.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH 4/4] session: kill a session of a closed connection' \
    /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