Skip to content

Protect TCP_NODELAY changes while sending headers - #172

Merged
floitsch merged 4 commits into
mainfrom
fix-send-headers-nodelay
Aug 19, 2026
Merged

floitsch merged 4 commits into
mainfrom
fix-send-headers-nodelay

Conversation

@floitsch

@floitsch floitsch commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

A peer disconnect can let the terminating header write succeed but make the following TCP_NODELAY restoration throw. In that case send-headers exits before returning the body writer, leaving Connection.current-writer_ set while ResponseWriter.body-writer_ is null. Later cleanup then fails with Previous request not completed.

Keep the TCP_NODELAY disable inside the guarded header-send sequence and restore TCP_NODELAY in finally after the complete header is written. A nested success flag closes and resets the connection if restoration itself throws without masking a header-write failure.

The regression test now checks specifically for Previous request not completed. Other close traces vary by OS and SDK, including an intermittent SDK-level Success read error, and are outside this regression.

Fixes the failure in https://github.com/toitlang/pkg-http/actions/runs/32307179434/job/96242345996

Validation:

  • Toit analysis with warnings as errors
  • Focused regression repeated 50 times
  • 12/12 local non-external tests

@floitsch
floitsch merged commit 9edcd6a into main Aug 19, 2026
7 checks passed
@floitsch
floitsch deleted the fix-send-headers-nodelay branch August 19, 2026 22:25
floitsch added a commit that referenced this pull request Oct 2, 2026
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 (seen on #174:
https://github.com/toitlang/pkg-http/actions/runs/37032094927/job/110921188938).

Both TCP_NODELAY changes in `send-headers` now go through a helper that
reports this error as `Connection closed`. Other errors propagate
unchanged, and the existing cleanup from #172 still closes the
connection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant