Skip to content

[Bugfix] Handle SocketException on accepted socket configuration#1648

Open
hamdaankhalid wants to merge 1 commit intomicrosoft:mainfrom
hamdaankhalid:hkhalid/more-tcp-fixes
Open

[Bugfix] Handle SocketException on accepted socket configuration#1648
hamdaankhalid wants to merge 1 commit intomicrosoft:mainfrom
hamdaankhalid:hkhalid/more-tcp-fixes

Conversation

@hamdaankhalid
Copy link
Copy Markdown
Contributor

Wrap the post-accept socket configuration in a try/catch, dispose the dead socket, and continue the accept loop. There is small gap where bad timing can still kill accept loop.

Copilot AI review requested due to automatic review settings March 27, 2026 21:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the TCP accept loop in GarnetServerTcp by ensuring post-accept socket configuration and handler registration failures don’t terminate the accept loop, disposing failed sockets/handlers and continuing to accept new connections.

Changes:

  • Wrap accepted-socket configuration (e.g., NoDelay, RemoteEndPoint access) inside the existing handler creation/registration try/catch.
  • Ensure sockets are disposed when handler creation never occurs (e.g., dead socket timing window).
  • Make handler cleanup more explicit (avoid null-conditional disposal paths).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hamdaankhalid hamdaankhalid force-pushed the hkhalid/more-tcp-fixes branch 2 times, most recently from db8e542 to 65af274 Compare March 27, 2026 22:03
@hamdaankhalid hamdaankhalid requested a review from Copilot March 27, 2026 22:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

When a client RSTs between accept completing and socket setup (e.g. NoDelay),
the SocketException was unhandled and crashed the process. Wrap the post-accept
socket configuration in a try/catch, dispose the dead socket, and continue
the accept loop.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hamdaankhalid hamdaankhalid force-pushed the hkhalid/more-tcp-fixes branch from 65af274 to f27d3e2 Compare March 27, 2026 22:16
}
else
{
if (ex is SocketException se)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it would be cleaner to catch this exception, however I am not sure of what other exceptions are possible with the 2 lines I moved in the try catch block. So for now I am adding this if-else here as well.

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.

2 participants