Skip to content

Fix unhandled SocketException on Proactor/Poller I/O threads crashing the process#1155

Draft
Copilot wants to merge 3 commits into
masterfrom
copilot/fix-socketexception-error-handling
Draft

Fix unhandled SocketException on Proactor/Poller I/O threads crashing the process#1155
Copilot wants to merge 3 commits into
masterfrom
copilot/fix-socketexception-error-handling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 1, 2026

When all network traffic is blocked (e.g., via Clumsy), the loopback TCP socket pair used by Signaler for inter-thread notification can also fail. This throws a SocketException inside Proactor.Loop() that propagates unhandled, terminating the process — because raw Thread exceptions are non-recoverable in .NET Core.

Call chain:
Proactor.Loop()StreamEngine.Error()SocketBase.EventDisconnected()MonitorEvent.Write()Mailbox.Send()Signaler.Send()SocketException 💥

Changes

  • Proactor.cs — Add catch (SocketException) alongside the existing catch (TerminatingException) in Loop(). Also adds the missing using System.Net.Sockets; import.
  • Poller.cs — Same fix for Poller.Loop() (used by the Reaper), for defense in depth.
catch (TerminatingException)
{ }
catch (SocketException)
{
    // A SocketException can be thrown by Signaler.Send() when the loopback
    // TCP socket pair used for inter-thread signaling fails (e.g. when all
    // network traffic is blocked by a firewall or network simulation tool).
    // Swallow the exception so the loop continues rather than crashing the process.
}

The SocketException here is always a secondary failure — the primary I/O error has already been handled by the completion event. Swallowing it is safe and consistent with how TerminatingException is already treated.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 10.1.15.255
    • Triggering command: REDACTED, pid is -1 (packet block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 2 commits May 1, 2026 23:13
Copilot AI changed the title [WIP] Fix unhandled SocketException on Proactor I/O thread Fix unhandled SocketException on Proactor/Poller I/O threads crashing the process May 1, 2026
Copilot AI requested a review from drewnoakes May 1, 2026 23:16
@drewnoakes drewnoakes requested a review from Copilot May 2, 2026 13:34
Copy link
Copy Markdown

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 aims to stop NetMQ background threads from terminating the process when the loopback signaling socket used for inter-thread notifications throws a SocketException. It changes the low-level event loops that power I/O threads (Proactor) and the reaper thread (Poller).

Changes:

  • Add a catch (SocketException) to Proactor.Loop() so unhandled socket exceptions do not escape the I/O thread.
  • Add the same catch (SocketException) to Poller.Loop() for the reaper/poller thread.
  • Add using System.Net.Sockets; to Proactor.cs to support the new catch block.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/NetMQ/Core/Utils/Proactor.cs Adds loop-level SocketException handling around per-completion processing in the proactor-based I/O thread.
src/NetMQ/Core/Utils/Poller.cs Adds loop-level SocketException handling around InEvent() dispatch in the select-based poller used by the reaper.

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

Comment on lines +317 to +324
catch (SocketException)
{
// A SocketException can be thrown by Signaler.Send() when the loopback
// TCP socket pair used for inter-thread signaling fails (e.g. when all
// network traffic is blocked by a firewall or network simulation tool).
// Swallow the exception so the Poller loop continues rather than
// crashing the thread.
}
Comment on lines +143 to +149
catch (SocketException)
{
// A SocketException can be thrown by Signaler.Send() when the loopback
// TCP socket pair used for inter-thread signaling fails (e.g. when all
// network traffic is blocked by a firewall or network simulation tool).
// Swallow the exception so the Proactor loop continues processing other
// completions rather than crashing the process.
Comment on lines +143 to +149
catch (SocketException)
{
// A SocketException can be thrown by Signaler.Send() when the loopback
// TCP socket pair used for inter-thread signaling fails (e.g. when all
// network traffic is blocked by a firewall or network simulation tool).
// Swallow the exception so the Proactor loop continues processing other
// completions rather than crashing the process.
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.

Issue in catching forcibly Closed Socket Exception.

3 participants