Skip to content

Commit

Permalink
Merge pull request #27 from ruby/fix-connection-leak-when-thread-inte…
Browse files Browse the repository at this point in the history
…rrupted

Fix connection leak when the thread is interrupted by Thread#kill etc.
  • Loading branch information
shugo committed Dec 15, 2023
2 parents 7ff7ca2 + a72fd9f commit 6be2f7e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/net/ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ def makepasv # :nodoc:
def transfercmd(cmd, rest_offset = nil) # :nodoc:
if @passive
host, port = makepasv
succeeded = false
begin
conn = open_socket(host, port)
if @resume and rest_offset
Expand All @@ -577,9 +578,9 @@ def transfercmd(cmd, rest_offset = nil) # :nodoc:
if !resp.start_with?("1")
raise FTPReplyError, resp
end
rescue Exception
conn&.close
raise
succeeded = true
ensure
conn&.close if !succeeded
end
else
sock = makeport
Expand Down

0 comments on commit 6be2f7e

Please sign in to comment.