Skip to content

Fix #747: Prevent double-close of accepted socket in HttpServer - #750

Open
NITIN9181 wants to merge 1 commit into
quickfix:masterfrom
NITIN9181:fix-issue-747
Open

Fix #747: Prevent double-close of accepted socket in HttpServer#750
NITIN9181 wants to merge 1 commit into
quickfix:masterfrom
NITIN9181:fix-issue-747

Conversation

@NITIN9181

Copy link
Copy Markdown

Resolves #747.

Description of the fix:
This PR fixes an issue where HttpServer would double-close an accepted socket file descriptor. Previously, when an HTTP request finished, HttpConnection::disconnect() would close the socket, and then SocketMonitor::drop(s) would close it again. This could result in a severe "FD theft" bug if the OS reassigned the file descriptor to a different thread in between the two closures.

Changes made:

  • Added a private m_closed boolean flag to HttpConnection to accurately track the connection's logical state without relying on OS-level socket closures.
  • Removed the socket_close(m_socket) call inside HttpConnection::disconnect(). This leaves the socket open so that SocketMonitor::drop(s) can safely close the FD exactly once.
  • Updated the success return condition in HttpConnection::read() from return true; to return !m_closed;. This ensures the read loop gracefully terminates if disconnect() is called during request processing, handing control back to HttpServer::onConnect.

All local tests pass, and the changes conform to the QuickFIX coding guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] HttpServer double-closes accepted socket fd per request, causing unintended close of another thread's fd

1 participant