Skip to content

Commit 5e722f2

Browse files
authored
fix: conn leak when watch timed out (#165)
Signed-off-by: spacewander <[email protected]>
1 parent db9e948 commit 5e722f2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/resty/etcd/v3.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,12 @@ local function request_chunk(self, method, path, opts, timeout)
716716
" body: ", body, " query: ", query)
717717

718718
if not res then
719+
http_cli:close()
719720
return nil, err
720721
end
721722

722723
if res.status >= 300 then
724+
http_cli:close()
723725
return nil, "failed to watch data, response code: " .. res.status
724726
end
725727

@@ -730,6 +732,7 @@ local function request_chunk(self, method, path, opts, timeout)
730732
while(1) do
731733
local chunk, read_err = res.body_reader()
732734
if read_err then
735+
http_cli:close()
733736
return nil, read_err
734737
end
735738
if not chunk then
@@ -757,18 +760,21 @@ local function request_chunk(self, method, path, opts, timeout)
757760

758761
local chunks, split_err = split(body, [[\n]], "jo")
759762
if split_err then
763+
http_cli:close()
760764
return nil, "failed to split chunks: " .. split_err
761765
end
762766

763767
local all_events = {}
764768
for _, chunk in ipairs(chunks) do
765769
body, err = decode_json(chunk)
766770
if not body then
771+
http_cli:close()
767772
return nil, "failed to decode json body: " .. (err or " unknown")
768773
elseif body.error and body.error.http_code >= 500 then
769774
-- health_check retry should do nothing here
770775
-- and let connection closed to create a new one
771776
health_check.report_failure(endpoint.http_host)
777+
http_cli:close()
772778
return nil, endpoint.http_host .. ": " .. body.error.http_status
773779
end
774780

0 commit comments

Comments
 (0)