Skip to content

Commit

Permalink
fix(telemetry): fix websocket connection leaks during reconnection (#…
Browse files Browse the repository at this point in the history
…10214)

When a WebSocket connection to analytics fails (for example, due to certificate validation issues), telemetry will attempt to reconnect without actively closing the previously established connection. The Lua VM's garbage collection does not immediately recycle the WebSocket connection after the function returns. So we need to close the connection proactively to avoid connection leaks.

https://konghq.atlassian.net/browse/KAG-5256
  • Loading branch information
chobits authored Sep 10, 2024
1 parent f8d73e0 commit 749de65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: Fixed a connection leak issue where the websocket connection was not closed promptly during reconnection.
type: bugfix
scope: Clustering
4 changes: 4 additions & 0 deletions kong/clustering/telemetry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ local function telemetry_communicate(premature, self, uri, server_name, on_conne

local res, err = c:connect(uri, opts)
if not res then
-- close it proactively to avoid connection leaks (CLOSE-WAIT) if the Lua VM
-- does not recycle it in time
c:close()

local delay = math.random(5, 10)

ngx_log(ngx_ERR, "connection to control plane ", uri, " broken: ", err,
Expand Down

0 comments on commit 749de65

Please sign in to comment.