Fix HttpServer double-close of accepted socket fd - #748
Open
raphaelroshan wants to merge 1 commit into
Open
Conversation
HttpConnection::disconnect() closed the accepted socket directly, and HttpServer::onConnect() then closed it again via SocketMonitor::drop() (the fd is monitor-tracked through SocketServer::accept()). If the fd number was recycled between the two closes, the second close silently tore down an unrelated socket. Delegate the close to the monitor, matching SocketConnection::disconnect(). onConnect() always drops after the read loop, so the socket is still closed exactly once. Adds a Catch2 test that reproduces the double close via fd reuse. Fixes quickfix#747
raphaelroshan
marked this pull request as ready for review
July 11, 2026 14:51
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.
What
HttpConnection::disconnect()no longer callssocket_close()directly.Why
HttpServer::onConnect()closes each accepted socket twice per request: once inHttpConnection::disconnect()and again viaSocketMonitor::drop(s)(the acceptedfd is monitor-tracked through
SocketServer::accept()→addConnect()). If the fdnumber is recycled between the two closes, the second close silently tears down an
unrelated socket — including one owned by another thread.
This mirrors
SocketConnection::disconnect(), which already delegates the close toSocketMonitor::drop()rather than closing the descriptor itself.HttpConnectionis only ever instantiated in
onConnect(), which always callsdrop(s)after theread loop, so the socket is still closed exactly once — no leak.
Test
Added
HttpConnectionTestCase.cpp, which reproduces the double close via fd reuse:after the read loop, a freshly opened socket reclaims the just-freed descriptor and
the subsequent
drop()must not close it. Fails onmaster, passes with this fix.Fixes #747