Skip to content

Commit

Permalink
fix(*) properly check worker_events.post_local() ret values (#3692)
Browse files Browse the repository at this point in the history
This function can return one of:

1. `true, nil`
2. `nil, err`
3. `false, nil`

Case 3. occurs when the library is already polling, likely in situations
with busy Admin API workloads. Because our return values check were
incorrect, some error logs would appear such as:

```
[error] 32#0: *6883 [lua] handler.lua:218: [events] could not broadcast crud event: nil, client: 10.x.x.x, server: kong, request: "POST /auth/oauth2/token HTTP/1.1"
```
  • Loading branch information
thibaultcha committed Aug 11, 2018
1 parent 7b3d5da commit 5ad6048
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions kong/db/dao/init.lua
Expand Up @@ -501,13 +501,13 @@ end

function DAO:post_crud_event(operation, entity)
if self.events then
local ok, err = self.events.post_local("dao:crud", operation, {
local _, err = self.events.post_local("dao:crud", operation, {
operation = operation,
schema = self.schema,
new_db = true,
entity = entity,
})
if not ok then
if err then
log(ERR, "[db] failed to propagate CRUD operation: ", err)
end
end
Expand Down
8 changes: 4 additions & 4 deletions kong/runloop/handler.lua
Expand Up @@ -213,15 +213,15 @@ return {
data.operation)

-- crud:routes
local ok, err = worker_events.post_local("crud", entity_channel, data)
if not ok then
local _, err = worker_events.post_local("crud", entity_channel, data)
if err then
log(ngx.ERR, "[events] could not broadcast crud event: ", err)
return
end

-- crud:routes:create
ok, err = worker_events.post_local("crud", entity_operation_channel, data)
if not ok then
_, err = worker_events.post_local("crud", entity_operation_channel, data)
if err then
log(ngx.ERR, "[events] could not broadcast crud event: ", err)
return
end
Expand Down

0 comments on commit 5ad6048

Please sign in to comment.