Skip to content

Keep server TLS handshakes off the accept loop - #618

Merged
bsergean merged 4 commits into
masterfrom
fix/concurrent-tls-accept
Oct 16, 2026
Merged

bsergean merged 4 commits into
masterfrom
fix/concurrent-tls-accept

Conversation

@bsergean

@bsergean bsergean commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

An idle TCP peer currently holds the server's only accept loop while TLS waits for its ClientHello. Other clients cannot finish connecting until that peer disconnects or the native backend's handshake times out.

Run TLS handshakes in tracked connection workers for Network.framework, OpenSSL and mbedTLS. Give server handshakes a 10-second deadline, cancel them during shutdown, and count pending workers toward the connection limit. Keep the stop flag set until those workers have exited. OpenSSL and mbedTLS wait for socket readiness instead of spinning when TLS needs more I/O.

Preserve the existing one-argument socket accept API and add a cancellable overload. Share the worker lifecycle between native and BSD-backed listeners, including socket cleanup and termination notification on handshake failure.

Add a dedicated mac_network_framework CI check using the same simple workflow layout as Linux. It calls make -f makefile.dev test_network_framework, which:

  • Selects Network.framework explicitly, with other TLS backends disabled.
  • Builds with strict C++11 and deprecated API warnings treated as errors.
  • Verifies the library's C++11 compile flags, reported native backend, and absence of OpenSSL linkage.
  • Runs the full test suite, including native client/server/mTLS and the new concurrent-handshake regressions.

Correct the macOS OpenSSL TSAN make target's misspelled backend flag so that job actually tests OpenSSL. Make ws --version return success so CI can verify its output normally.

Validation:

  • Concurrent acceptance, shutdown cancellation, pending limits, slot recovery and timeout passed locally with Network.framework, OpenSSL and mbedTLS.
  • Connection, reconnect, close and send-timeout integration tests passed with all three backends.
  • All eight CI checks passed, including the dedicated Network.framework full suite, Linux/ASAN, macOS TSAN backends, Windows GCC and UWP.
  • Putting the handshake back on the accept thread makes the concurrent-client regression fail. Removing pending-worker accounting makes the connection-limit regression fail.
  • Strict native C++11 build and deprecated-API checks, workflow YAML parsing, formatting and git diff --check passed.

An idle TCP peer must not occupy the server's only accept loop while TLS
waits for a ClientHello. Move TLS acceptance to tracked connection workers
for Network.framework and BSD-backed servers, with a ten-second deadline
and cancellation during shutdown. Keep the stop flag set until the workers
have exited, and include pending workers in the connection limit.

Add cancellable accept overloads while keeping the existing entry point.
OpenSSL and mbedTLS poll for socket readiness instead of spinning while a
handshake needs more I/O. Failed handshakes release their socket through
its owner and notify the connection thread collector.

Test concurrent acceptance, shutdown cancellation, limits, slot recovery
and timeout with all three TLS server backends. Share test credential
generation, include the regressions in the native make target, and fix the
OpenSSL TSAN target's misspelled backend flag so it actually tests OpenSSL.
Build with C++11 and deprecated API errors, verify the native backend and absence of OpenSSL linkage, then run the full test suite. Return success from ws --version so backend verification can check the command result.
The TLS backend can close its socket before the connection worker reports the timeout. Synchronize the test with that notification instead of sampling a counter immediately after EOF. Print failing test output in the OpenSSL TSAN target.
@bsergean
bsergean merged commit e8c76ec into master Oct 16, 2026
8 checks passed
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.

1 participant