Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(clustering/rpc): generate rpc disconnected event #14077

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions kong/clustering/rpc/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,17 @@ function _M:handle_websocket()
local res, err = s:join()
self:_remove_socket(s)

-- tell outside that rpc disconnected
do
local worker_events = assert(kong.worker_events)

-- notify this worker
local ok, err = worker_events.post_local("clustering:jsonrpc", "disconnected")
if not ok then
ngx_log(ngx_ERR, _log_prefix, "unable to post rpc disconnected event: ", err)
end
end

if not res then
ngx_log(ngx_ERR, _log_prefix, "RPC connection broken: ", err, " node_id: ", node_id)
return ngx_exit(ngx.ERROR)
Expand Down
7 changes: 6 additions & 1 deletion kong/clustering/services/sync/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function _M:init_worker()
-- cp does not support kong.sync.v2
if not has_sync_v2 then
ngx.log(ngx.WARN, "rpc sync is disabled in CP.")
assert(self.rpc:sync_every(EACH_SYNC_DELAY), true) -- stop timer
assert(self.rpc:sync_every(EACH_SYNC_DELAY, true)) -- stop timer
return
end

Expand All @@ -86,6 +86,11 @@ function _M:init_worker()
assert(self.rpc:sync_every(EACH_SYNC_DELAY))

end, "clustering:jsonrpc", "connected")

-- if rpc is down we will also stop to sync
worker_events.register(function()
assert(self.rpc:sync_every(EACH_SYNC_DELAY, true)) -- stop timer
end, "clustering:jsonrpc", "disconnected")
end


Expand Down
Loading