Repository navigation
Lingering close for HTTP and WebSocket servers; half-close API (#21) - #23
Merged
Merged
Conversation
…urnloop-io linger_close AsyncIo gains poll_shutdown (flush, then the backend's stream shutdown without closing the handle), executor() and is_write_shut(). Writes after a half-close fail. Unix rejects shutdown on non-socket descriptors with Unsupported; IOCP already did for pipes and synchronous handles. turnloop-io adds the HalfClose trait (AsyncIo, TlsStream, Transport), a shutdown helper next to the unchanged close, and linger_close: half-close, read and discard into caller scratch until peer EOF or a deadline, then close. It waits on one read and one executor timer, allocates nothing per read, and bounds the half-close by the same deadline. TlsStream refuses writes after close_notify. Tests: half-close semantics, EOF-driven and deadline-driven lingering (no-spin turn bound), a stalled half-close, UDP Unsupported, TLS half-close, and a real-TCP allocation gate for the discard path (issue #21).
server::http1 and server::http2 no longer close a drained connection while peer bytes are unread, which sent RST and on macOS and Windows could discard the peer's unread final response (Node HTTP/2 client: read ECONNRESET). After the final response and GOAWAY are flushed they half-close, discard peer input until EOF or the linger deadline, then close. Idle HTTP/1 keep-alive connections at shutdown linger too. server::Options::linger_timeout (default 5 s) configures the bound; Shutdown::stop_by(deadline) closes lingering connections by an overall shutdown deadline, re-arming ones already lingering. WebSocketStream::close lingers under its close deadline. Deterministic tests hold the peer's reads until the server has closed and make its late bytes (a pipelined request; SETTINGS ACK, WINDOW_UPDATE, PING) unread at that moment, over TCP and TLS; with the old close they fail with ECONNRESET or EPIPE every run. Plus linger timeout and stop_by no-spin tests, an idle keep-alive shutdown test, a WebSocket server close test and an HTTP server allocation gate for the discard phase.
The settle turns before the no-spin measurement must not overrun the linger deadline on a slow runner. docs/lanes/linger-close.md records the root cause, API, per-platform behaviour, the no-fix and mutation evidence and every verification command.
|
Warning Review limit reachedNext included review available in 32 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (20)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…e acknowledgement server_allocations assumed paced 200 us writes would arrive as mostly separate reads; Linux coalesced them (fewer than 128 of 256). Both discard allocation gates now lock-step the peer on the server's published discard progress, so every chunk is its own read on any kernel: reads >= 256, discarded == 1024, allocations == 0. On WASI 0.3 the backend closes the send stream (the peer reads EOF) and completes Shutdown only when the stream's result future resolves in a later wait-set step, so the peer can finish before the server observes its own half-close. The HTTP silent-peer helper and the turnloop-io silent-peer test now turn until the server has observed its half-close before settling and measuring; the no-spin bounds are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21. Report:
docs/lanes/linger-close.md.Root cause
Servers closed the socket while the peer still had unread bytes, which sends RST instead of FIN.
ECONNRESET. That's what the Node HTTP/2 client hit in Queued turns never block; count zero-timeout discovery polls separately (I01) #20.WebSocketStream::close. An idle HTTP/1 keep-alive connection was also dropped at shutdown.API
turnloopAsyncIo::poll_shutdown: flushes, then shuts down the write side without closing the handle; reads continue until EOF.shutdown(send), WASI 0.3 closing the send stream).turnloop-io:HalfClosetrait forAsyncIo,TlsStreamandTransport, plus ashutdown()helper.linger_close(stream, scratch, deadline): half-close, discard until EOF or the deadline, close. It reportsLingered { end, reads, discarded }.turnloop-tls: shutdown sends close_notify, then half-closes TCP. Writes after close_notify are refused. This also fixes a bug where a rejected record blocked later reads.turnloop-http:server::Options { linger_timeout }(default 5 s, like nginx),Server::bind_with,Shutdown::with_optionsandShutdown::stop_by(deadline).Behaviour
Tests (each fails with the old close)
reset before EOF.Broken pipeon the client's close_notify.ConnectionResetbefore.stop_bytests catch an injected self-wake.turnloop-ioand the newturnloop-http/tests/server_allocations.rsboth catch an injected allocation.Verification
Local: macOS native (266 tests default, 333 all-features), all 9 interop suites in each mode, WASI 0.2 runtime, strict clippy for native, Linux, Windows, wasip2 and web, no-tokio and soak. Linux, Windows, WASI 0.3, web and h2spec run in this PR's CI.