diff --git a/test/box/gh-4627-session-use-after-free.result b/test/box/gh-4627-session-use-after-free.result index 5e5c154b92dc63714c2a0eeb161d943e4ea7ba98..29144b0983299fe6e58e0382d95aef2e3a9fd647 100644 --- a/test/box/gh-4627-session-use-after-free.result +++ b/test/box/gh-4627-session-use-after-free.result @@ -20,6 +20,22 @@ fiber = require('fiber') | --- | ... +box.schema.user.grant('guest', 'execute', 'universe') + | --- + | ... + +-- This is a workaround for flakiness of the test +-- appearing when test-run does reconnects to the +-- instance and therefore creates multiple +-- sessions. 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 +43,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,9 +56,11 @@ end) connection = net_box.connect(box.cfg.listen) | --- | ... -connection:ping() +-- 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') | --- - | - true | ... connection:close() | --- @@ -58,3 +79,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 70624a96a4e0d0edc2da961f9a76def49f16e7e6..18d56e2035531cff7be818be96503c4a02f9e08d 100644 --- a/test/box/gh-4627-session-use-after-free.test.lua +++ b/test/box/gh-4627-session-use-after-free.test.lua @@ -15,16 +15,34 @@ 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 test-run does reconnects to the +-- instance and therefore creates multiple +-- sessions. 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) -connection:ping() +-- 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:close() while not sid_after_yield do fiber.yield() end @@ -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')