From 16fbcefdf8b2de6a80598e7dd508592354f25582 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Fri, 2 Oct 2026 18:54:57 +0200 Subject: [PATCH] Treat EINVAL from TCP_NODELAY as a closed connection macOS rejects setsockopt with EINVAL once the peer has reset the connection. When this happened while sending request headers on a reused connection, the client saw "Invalid argument", which is-close-exception_ doesn't recognize, so the request wasn't retried even with --retry-on-connection-close. This made client-request-retry-test flaky on macOS. Route both TCP_NODELAY changes in send-headers through a helper that reports this error as "Connection closed". The existing cleanup still closes the connection. --- src/connection.toit | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/connection.toit b/src/connection.toit index d50110b..d351ae6 100644 --- a/src/connection.toit +++ b/src/connection.toit @@ -148,7 +148,7 @@ class Connection: headers-written := false no-delay-restored := false try: - socket_.no-delay = false + set-no-delay_ false writer.write status headers.write-to writer if is-client-request and host_: @@ -162,7 +162,7 @@ class Connection: // finally ensures that we still close while its exception propagates. try: if headers-written: - socket_.no-delay = true + set-no-delay_ true no-delay-restored = true finally: // A partial header or a failed TCP_NODELAY restoration makes the @@ -173,6 +173,13 @@ class Connection: return body-writer + set-no-delay_ value/bool -> none: + exception := catch --unwind=(: it != "Invalid argument"): + socket_.no-delay = value + // macOS rejects socket options with EINVAL once the peer has reset the + // connection. Report that as a close, so that clients can retry. + if exception: throw "Connection closed" + // Gets the next request from the client. If the client closes the // connection, returns null. read-request -> RequestIncoming?: