Skip to content

Commit

Permalink
fix(pdk/vault): do not call sema:wait in init phase (#9851)
Browse files Browse the repository at this point in the history
* do not call sema:wait in init phase
* changelog
  • Loading branch information
chronolaw authored Dec 1, 2022
1 parent ef0f55b commit 62cbf1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@
and body parameter type of `kong.response.exit` to bytes. Note that old
version of go PDK is incompatible after this change.
[#9526](https://github.com/Kong/kong/pull/9526)
- Vault will not call `semaphore:wait` in `init` or `init_worker` phase.
[#9851](https://github.com/Kong/kong/pull/9851)

#### Plugins

Expand Down
19 changes: 15 additions & 4 deletions kong/pdk/vault.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local cjson = require("cjson.safe").new()


local ngx = ngx
local get_phase = ngx.get_phase
local fmt = string.format
local sub = string.sub
local byte = string.byte
Expand Down Expand Up @@ -507,10 +508,20 @@ local function new(self)
return callback(options)
end

-- grab a semaphore to limit concurrent updates to reduce calls to vaults
local wait_ok, wait_err = RETRY_SEMAPHORE:wait(RETRY_WAIT)
if not wait_ok then
self.log.notice("waiting for semaphore failed: ", wait_err or "unknown")
local wait_ok
local phase = get_phase()

if phase == "init" or phase == "init_worker" then
-- semaphore:wait can't work in init/init_worker phase
wait_ok = false

else
-- grab a semaphore to limit concurrent updates to reduce calls to vaults
local wait_err
wait_ok, wait_err = RETRY_SEMAPHORE:wait(RETRY_WAIT)
if not wait_ok then
self.log.notice("waiting for semaphore failed: ", wait_err or "unknown")
end
end

-- do we now have values with RETRY_TTL seconds ttl?
Expand Down

3 comments on commit 62cbf1d

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker image avaialble kong/kong:master-apk
Artifacts availabe https://github.com/Kong/kong/actions/runs/3591331493

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker image avaialble kong/kong:master-rpm
Artifacts availabe https://github.com/Kong/kong/actions/runs/3591331493

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker image avaialble kong/kong:master-deb
Artifacts availabe https://github.com/Kong/kong/actions/runs/3591331493

Please sign in to comment.