Repository navigation
Add gracefulCloseWith, given up on through STM - #658
Merged
Merged
Conversation
kazu-yamamoto
added a commit
to kazu-yamamoto/network
that referenced
this pull request
Nov 17, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
recvBufNoWait on Windows now tells the end of the data (0) from nothing to read (-1), as on POSIX. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wins Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kazu-yamamoto
force-pushed
the
graceful-close-with
branch
from
November 19, 2026 23:37
bb54533 to
3faa5bd
Compare
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.
For #618: the part a graceful-close manager needs from
network, which can then stop pending closes withoutthrowTo.gracefulCloseWith :: Socket -> STM a -> IO (Either a Drained), andunsafeGracefulCloseWith, given up on through anSTMaction as the other...Withfunctions are.Leftwhen it gave up;Right PeerClosedwhen the peer's FIN came (or the connection was already gone),Right DrainLimitwhen the peer sent 128 KiB without closing. The socket is closed either way.gracefulCloseandunsafeGracefulCloseare built on them with aregisterDelaydeadline, unchanged in behaviour; the non-threaded RTS keeps itstimeoutpath.gracefulCloseandgracefulCloseWithend withclose, whosecloseFdWithwakes any other thread waiting on the socket;unsafeGracefulCloseandunsafeGracefulCloseWithend withunsafeClose, for a caller which knows no other thread is waiting on it.gracefulClosementions the drain limit.recvBufNoWaitonce the socket is readable, so a thread which loses the data to another reader (as when a close runs twice at once, CLOSE_WAIT #590) waits again under the give-up instead of blocking past it.recvBufNoWaiton Windows callsrecvdirectly, as the socket is now non-blocking: it returns 0 at the end of the data rather than -1, as on POSIX.gracefulClosewait about its timeout;gracefulCloseWithreportsPeerClosed, gives up when told to, gives up even if another thread takes the data (this one hangs with the old drain), and cuts off a peer which keeps sending;recvBufNoWaittells -1 from 0.Tested locally on Linux, macOS and Windows (WinIO).
🤖 Generated with Claude Code