From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp14.mail.ru (smtp14.mail.ru [94.100.181.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5220246971A for ; Tue, 3 Dec 2019 03:05:34 +0300 (MSK) From: Vladislav Shpilevoy Date: Tue, 3 Dec 2019 01:05:30 +0100 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/1] test: fix flaky box/gh-4627-session-use-after-free List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, alexander.turenko@tarantool.org The problem was in that the test uses the global trigger box.session.on_disconnect() to set a global variable by one connection. But test-run can do multiple connects/reconnects to the same instance. That led to multiple invocations of box.session.on_disconnect(), which could override the global variable in unexpected ways and moments. The patch makes only one session execute that trigger. Probably related to https://github.com/tarantool/test-run/issues/46 Follow up #4627 --- Branch: https://github.com/tarantool/tarantool/tree/gerold103/session-flaky-test .../box/gh-4627-session-use-after-free.result | 28 +++++++++++++++++++ .../gh-4627-session-use-after-free.test.lua | 20 +++++++++++++ 2 files changed, 48 insertions(+) diff --git a/test/box/gh-4627-session-use-after-free.result b/test/box/gh-4627-session-use-after-free.result index 5e5c154b9..33e5a7af1 100644 --- a/test/box/gh-4627-session-use-after-free.result +++ b/test/box/gh-4627-session-use-after-free.result @@ -20,6 +20,21 @@ fiber = require('fiber') | --- | ... +box.schema.user.grant('guest', 'execute', 'universe') + | --- + | ... + +-- This is a workaround for flakiness of the test +-- appearing when another test tries to connect to +-- this one. By setting a flag for only one +-- session, others won't interfere in +-- session.on_disconnect(). +function enable_on_disconnect() \ + box.session.storage.is_enabled = true \ +end + | --- + | ... + sid_before_yield = nil | --- | ... @@ -27,6 +42,9 @@ sid_after_yield = nil | --- | ... func = box.session.on_disconnect(function() \ + if not box.session.storage.is_enabled then \ + return \ + end \ sid_before_yield = box.session.id() \ fiber.yield() \ sid_after_yield = box.session.id() \ @@ -37,6 +55,12 @@ end) connection = net_box.connect(box.cfg.listen) | --- | ... +-- Connections, not related to this one, won't +-- call this function, and therefore won't do +-- anything in session.on_disconnect() trigger. +connection:call('enable_on_disconnect') + | --- + | ... connection:ping() | --- | - true @@ -58,3 +82,7 @@ sid_after_yield == sid_before_yield and sid_after_yield ~= 0 or \ box.session.on_disconnect(nil, func) | --- | ... + +box.schema.user.revoke('guest', 'execute', 'universe') + | --- + | ... diff --git a/test/box/gh-4627-session-use-after-free.test.lua b/test/box/gh-4627-session-use-after-free.test.lua index 70624a96a..1b2ebfdc4 100644 --- a/test/box/gh-4627-session-use-after-free.test.lua +++ b/test/box/gh-4627-session-use-after-free.test.lua @@ -15,15 +15,33 @@ net_box = require('net.box') fiber = require('fiber') +box.schema.user.grant('guest', 'execute', 'universe') + +-- This is a workaround for flakiness of the test +-- appearing when another test tries to connect to +-- this one. By setting a flag for only one +-- session, others won't interfere in +-- session.on_disconnect(). +function enable_on_disconnect() \ + box.session.storage.is_enabled = true \ +end + sid_before_yield = nil sid_after_yield = nil func = box.session.on_disconnect(function() \ + if not box.session.storage.is_enabled then \ + return \ + end \ sid_before_yield = box.session.id() \ fiber.yield() \ sid_after_yield = box.session.id() \ end) connection = net_box.connect(box.cfg.listen) +-- Connections, not related to this one, won't +-- call this function, and therefore won't do +-- anything in session.on_disconnect() trigger. +connection:call('enable_on_disconnect') connection:ping() connection:close() @@ -33,3 +51,5 @@ sid_after_yield == sid_before_yield and sid_after_yield ~= 0 or \ {sid_after_yield, sid_before_yield} box.session.on_disconnect(nil, func) + +box.schema.user.revoke('guest', 'execute', 'universe') -- 2.21.0 (Apple Git-122.2)