fix(Net): release FTPClientSession control socket on constructor failure; document readWelcomeMessage #5413 - #5418
Open
matejk wants to merge 2 commits into
Open
fix(Net): release FTPClientSession control socket on constructor failure; document readWelcomeMessage #5413#5418matejk wants to merge 2 commits into
matejk wants to merge 2 commits into
Conversation
Cover the FTP and FTPS StreamSocket constructors with tests for both values.
…rows The destructor does not run for a partially constructed object, so the socket stayed open and the peer never saw a disconnect.
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.
Documentation (#5413)
readWelcomeMessagehas been undocumented since it was added in #2335 (released in 1.10.0), and its name suggests "read it later" rather than "it was already read". #5413 questions the_serverReady = trueassignment in thefalsebranch. That assignment is intentional: without it, the nextlogin()blocks waiting for a welcome reply that was already consumed, andFTPSClientSessionstalls before sendingAUTH TLS. The behavior is unchanged in every release since 1.10.0.Documented in
FTPClientSession.handFTPSClientSession.h:readWelcomeMessagemeans, and that passingfalsewhile the welcome reply is still pending desynchronizes the session, because that reply is then taken as the response to the next commandwelcomeMessage()is empty when the caller read the replyreceiveServerReadyReply()does nothing once the server is marked readyControl socket leak
Found while writing the tests.
_pControlSocketis a raw pointer, so a constructor that throws never releases it: the destructor does not run for a partially constructed object. The socket stays open and the peer never sees a disconnect. This is reachable whenever the server answers with a negative welcome reply, for example421 Service not available, or the read times out.Both affected constructors now release the control socket and rethrow. The member type is unchanged, since it is protected and
FTPSClientSessiondereferences it directly, so switching to a smart pointer would break third-party subclasses.Tests
The
StreamSocketconstructor had no coverage at all. Added toFTPClientSessionTestandFTPSClientSessionTest:testWelcomeMessageRead/testWelcomeMessageNotReadcover both values of the flagtestConstructorFailureClosesSocket1/testConstructorFailureClosesSocket2cover the connection being closed after each constructor throwsThe leak tests use a plain
ServerSocketinstead ofDialogServer.DialogServeronly leaves its receive loop once the peer disconnects, so a leaked socket would hang the suite rather than fail it; the new tests assert the server side reaches EOF under a receive timeout. Each test was checked against a reverted fix to confirm it fails when the corresponding change is missing.Closes #5413.