Skip to content

Wait for an interrupted connect instead of reissuing it - #66

Open
Frauschi wants to merge 1 commit into
wolfSSL:mainfrom
Frauschi:connect-eintr
Open

Frauschi wants to merge 1 commit into
wolfSSL:mainfrom
Frauschi:connect-eintr

Conversation

@Frauschi

@Frauschi Frauschi commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

The built-in transport mishandled EINTR during connect: the blocking path reissued connect(), which BSD kernels answer with EALREADY/EISCONN, and the timed path restarted poll() with the full timeout after every signal.

Changes

  • A blocking connect stays blocking and polls for completion after EINTR instead of reissuing connect()
  • A timed connect polls non-blocking; after EINTR the poll resumes with the time left

Testing

  • test_net: a 300 ms connect to an unroutable address under a SIGALRM every 20 ms returns at its deadline, not before or after
  • test_net: a blocking connect leaves the socket blocking; net gets a 30 s ctest timeout

Fixes F-17353 and F-11054.

@Frauschi Frauschi self-assigned this Nov 13, 2026
Copilot AI balanced review requested due to automatic review settings November 13, 2026 13:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the POSIX connection-waiting and timeout-handling changes.

No open issues 🎉

What changed in this PR

Updates wolfCert’s built-in POSIX transport to wait for interrupted connections without reissuing connect() or extending configured timeouts.

Changes:

  • Uses non-blocking connect and polling for both blocking and timed calls, recalculating the remaining timeout after signals.
  • Adds regression tests for signal-interrupted timeouts and preservation of blocking socket mode.
  • Limits the net test to 30 seconds in CTest.
File Description
tests/​unit/​test_net.c Adds signal-driven timeout and blocking-mode regression tests.
tests/​CMakeLists.txt Sets a 30-second timeout for the net test.
src/​net_posix.c Unifies connection waiting and preserves deadlines across EINTR.

Review effort: Balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #66

Scan targets checked: wolfcert-bugs
Not reviewed (no scan target covers them): src/net_posix.c, tests/CMakeLists.txt
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

@Frauschi

Copy link
Copy Markdown
Member Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread src/net_posix.c Resolved
Comment thread tests/CMakeLists.txt Resolved
With no timeout, connect_timeout() retried connect() after EINTR. POSIX
lets an interrupted connect() finish in the background, and BSD-derived
kernels (macOS, FreeBSD) answer the second call with EALREADY while it is
in progress or EISCONN once it is done, so a signal during the connect
failed a connection that was about to succeed. On Linux the reissued call
waits, which hid this.

With a timeout, the poll() loop retried with the full timeout after each
EINTR, so a steady stream of signals kept the connect waiting forever.

With no timeout the connect stays blocking, so the platform's own limit
still applies (Zephyr bounds it by CONFIG_NET_SOCKETS_CONNECT_TIMEOUT),
and after EINTR it polls for writability instead of reissuing connect().
With a timeout it connects non-blocking and polls; after EINTR the poll
resumes with the time left before the deadline. A signal that lands
right at the deadline gets one last zero-wait poll, so a connect that
finished meanwhile still counts.

test_net runs a 300 ms connect to an unroutable address under a SIGALRM
every 20 ms and requires it back after 250 ms and within 3 s; the old
code never returned. On a host that refuses the address rather than
dropping it, the case is skipped and says so. A blocking connect to a
loopback listener must succeed and leave the socket blocking. The net
test gets a 30 s ctest timeout, so a regression fails instead of
hanging.

Fixes F-17353.
Fixes F-11054.
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.

4 participants