Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(synchronization): correctly cleanup key#1591

Merged
tkan145 merged 1 commit into
3scale:masterfrom
tkan145:refactor-synchronization
Jul 7, 2026
Merged

fix(synchronization): correctly cleanup key#1591
tkan145 merged 1 commit into
3scale:masterfrom
tkan145:refactor-synchronization

Conversation

@tkan145

@tkan145 tkan145 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What

Correctly release key

  • Create a test script called synchronization.lua inside benchmark folder
local root = require('pl.path').currentdir()
package.path = root .. '/?.lua;' ..
               root .. '/gateway/src/?.lua;' ..
               root .. '/gateway/src/apicast/policy/3scale_batcher/?.lua;' ..
               package.path

local synchronization = require('resty.synchronization').new(1)
local inspect = require 'inspect'

local function foo()
  print('calling foo')
end
local ret, result = synchronization:run("foo", 15, foo)
if not ret then
  print(' error: ', result)
end

print("semaphores: ", inspect(synchronization.semaphores))
  • Run with
make development
resty benchmark/synchronization.lua
  • Before
semaphores: {
  foo = {
    name = "foo",
    sem = cdata<struct ngx_http_lua_sema_s *>: 0x7f0b18c48028,
    <metatable> = {
      __index = {
        count = <function 1>,
        new = <function 2>,
        post = <function 3>,
        version = "0.1.31",
        wait = <function 4>
      }
    }
  },
  <metatable> = {
    __index = <function 5>
  }
}
  • After
semaphores: {
  <metatable> = {
    __index = <function 1>
  }
}

@tkan145 tkan145 requested a review from a team as a code owner June 15, 2026 02:49
eguzki
eguzki previously approved these changes Jun 25, 2026
Previously, synchronization.run called self.release(key), which sends the key
as self. Therefore, inside the release function, it becomes key.semaphore with
a nil value, so the key is never released.
@tkan145 tkan145 merged commit 531e21a into 3scale:master Jul 7, 2026
11 checks passed
@tkan145 tkan145 deleted the refactor-synchronization branch July 7, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants