Skip to content

Handle macOS EINVAL when enabling TCP_NODELAY on outbound TCP sockets - #1161

Merged
drewnoakes merged 2 commits into
masterfrom
copilot/fix-macos-github-actions-job
May 24, 2026
Merged

Handle macOS EINVAL when enabling TCP_NODELAY on outbound TCP sockets#1161
drewnoakes merged 2 commits into
masterfrom
copilot/fix-macos-github-actions-job

Conversation

Copilot AI commented May 24, 2026

Copy link
Copy Markdown
Contributor

The macOS CI job was aborting during the test run because the test host crashed in TcpConnector.OutCompleted while enabling NoDelay on a socket that had just connected. On macOS, this path can surface as SocketException(SocketError.InvalidArgument) rather than the ArgumentException the code already tolerated.

  • Root cause

    • TcpConnector.OutCompleted already treated NoDelay setup as best-effort on macOS, but only for ArgumentException.
    • Recent macOS runners are throwing SocketException with InvalidArgument for the same transient condition.
  • Change

    • Extend the existing guard around m_s.NoDelay = true to also ignore:
      • SocketException when SocketErrorCode == SocketError.InvalidArgument
    • Keep behavior unchanged for all other socket failures.
  • Impact

    • Prevents the macOS test host from crashing during async outbound TCP connect completion.
    • Preserves the existing intent: treat TCP_NODELAY as opportunistic during this narrow connection window.
try
{
    m_s.NoDelay = true;
}
catch (ArgumentException)
{
    // OSX sometime fail while the socket is still connecting
}
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.InvalidArgument)
{
    // macOS may report EINVAL here while the socket is still connecting.
}

Agent-Logs-Url: https://github.com/zeromq/netmq/sessions/839215c1-545a-4f5c-8937-94397dcbaed6

Co-authored-by: drewnoakes <350947+drewnoakes@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix failing GitHub Actions job macos Handle macOS EINVAL when enabling TCP_NODELAY on outbound TCP sockets May 24, 2026
Copilot AI requested a review from drewnoakes May 24, 2026 11:50
@drewnoakes
drewnoakes marked this pull request as ready for review May 24, 2026 12:16
@drewnoakes
drewnoakes merged commit cbe150e into master May 24, 2026
3 checks passed
@drewnoakes
drewnoakes deleted the copilot/fix-macos-github-actions-job branch May 24, 2026 12:22
follesoe added a commit to BluEye-Robotics/netmq that referenced this pull request Jul 20, 2026
…tener

Problem: a peer that connects and immediately resets the connection can
kill the whole process. When the RST lands between the proactor
completing an accept and InCompleted applying socket options to the
accepted socket, the option calls throw (EINVAL on macOS) on the
proactor thread, where nothing catches the exception.

Solution: treat setup failure as a failed accept, the way libzmq treats
tune_socket failure: dispose the accepted socket, raise
EventAcceptFailed and keep accepting. The guarded region includes the
StreamEngine construction, whose constructor also touches the socket
(send/receive buffer sizes). The monitor event reports ConnectionReset
rather than mapping the raw error through ToErrorCode, which
Debug.Asserts on unmapped values.

Accept-side sibling of the outbound-socket fix in zeromq#1161. Adds a
regression test that floods a listener with immediately-reset connects
and asserts it stays alive and accepting; without the fix it crashes
the test host 12/12 times on macOS arm64.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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