From f472617a7838d40271f56223b82ce0b489098e5c Mon Sep 17 00:00:00 2001 From: ProBrian Date: Thu, 19 Dec 2024 14:37:46 +0800 Subject: [PATCH] close socket connection when websocket connect failed to avoid potential leak --- kong/clustering/rpc/manager.lua | 1 + kong/clustering/utils.lua | 1 + 2 files changed, 2 insertions(+) diff --git a/kong/clustering/rpc/manager.lua b/kong/clustering/rpc/manager.lua index ea5c4f5a2822..44b166f440ed 100644 --- a/kong/clustering/rpc/manager.lua +++ b/kong/clustering/rpc/manager.lua @@ -559,6 +559,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 ee34e7dce2e4..bebef2f2daf5 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