diff --git a/changelog/unreleased/kong/fix-potential-socket-connection-leak.yml b/changelog/unreleased/kong/fix-potential-socket-connection-leak.yml new file mode 100644 index 000000000000..218bcca26a5f --- /dev/null +++ b/changelog/unreleased/kong/fix-potential-socket-connection-leak.yml @@ -0,0 +1,3 @@ +message: "Fix potential socket connection leak when websocket client connection fails" +type: bugfix +scope: Core diff --git a/kong/clustering/rpc/manager.lua b/kong/clustering/rpc/manager.lua index eefb1aabb6c5..c90bbb56b69b 100644 --- a/kong/clustering/rpc/manager.lua +++ b/kong/clustering/rpc/manager.lua @@ -569,6 +569,7 @@ function _M:connect(premature, node_id, host, path, cert, key) ::err:: if not exiting() then + c:close() self:try_connect(reconnection_delay) end end diff --git a/kong/clustering/utils.lua b/kong/clustering/utils.lua index f05be2353fbc..5959f8f0a837 100644 --- a/kong/clustering/utils.lua +++ b/kong/clustering/utils.lua @@ -106,6 +106,7 @@ function _M.connect_cp(dp, endpoint, protocols) local ok, err = c:connect(uri, opts) if not ok then + c:close() return nil, uri, err end