Repository navigation
Conversation
`connect` left the TCP socket open when the server rejected the session, for example with a 421 greeting, and `Net::FTP.new(host)` raised before returning an object the caller could close. `connect` now closes the socket when a step after `open_socket` raises. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Net::FTP#connectopens a TCP socket, reads the server greeting and, withssl:, sets up TLS. When the greeting or the TLS setup raises, the socket stays open. WithNet::FTP.new(host), the exception comes out of the constructor, so the caller never gets theNet::FTPobject and has no way to callclose. The socket stays open until garbage collection.This condition can occur when a busy server greets with
421, when the server rejectsAUTH TLS,PBSZorPROT P, or when the TLS handshake fails withimplicit_ftps: true. The421greeting is the most common case.connecthad arescueforOpenSSL::SSL::SSLErrorandNet::OpenTimeoutthat called@sock.close. The plain FTP path had norescue, and server replies such as421or502raiseNet::FTPErrorsubclasses, which therescuedid not catch. Withimplicit_ftps: true,@sockis assigned only after the handshake, so on a handshake failure therescueclosed the@sockfrom beforeconnectand left the new socket open.The
421greeting case goes back to the first version ofconnectin 986a74a, which read the greeting withvoidrespand had norescue. TheAUTH TLS,PBSZandPROT Pcases go back to bc82f22, which added TLS support with arescueforOpenSSL::SSL::SSLErroronly. The implicit FTPS case goes back to f75ff61, which skips the plain@sockassignment for implicit FTPS, so@sockis set only after the handshake.connectnow wraps the steps afteropen_socketinbegin/ensureand closes@bare_sockunless the steps finished, the same waytransfercmdhandles the data socket. After a failedconnect,closed?returns true.