Map POLLHUP to readEOF in the WSAPoll selector so remote half-closure works on Windows - #3715
Open
Budoman wants to merge 1 commit into
Open
Map POLLHUP to readEOF in the WSAPoll selector so remote half-closure works on Windows#3715Budoman wants to merge 1 commit into
Budoman wants to merge 1 commit into
Conversation
WSAPoll has no POLLRDHUP equivalent, so POLLHUP is the only hangup signal available and it covers both an orderly peer shutdown (FIN) and an abortive teardown (RST). The WSAPoll selector mapped it to .reset, which SelectableEventLoop.handleEvent treats as terminal: it tears the whole Channel down and skips the .read/.readEOF handling entirely. A peer's FIN therefore closed both directions of the Channel and allowRemoteHalfClosure could never be honoured on Windows, unlike epoll and kqueue. Report .readEOF instead, matching the event epoll synthesises from EPOLLRDHUP, and let the following recv distinguish the two cases: 0 for an orderly FIN, which readable0 turns into half-closure when the Channel allows it, and WSAECONNRESET/WSAECONNABORTED for an abort, which closes the Channel with the real error. This remains one-shot even though WSAPoll reports POLLHUP regardless of the requested events: readEOF0 drops .readEOF from the registration's interest and whenReady0 intersects each event set with registration.interested, so subsequent POLLHUP reports are masked and cannot spin the event loop.
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.
Motivation
On Windows,
allowRemoteHalfClosureis currently unimplementable: the WSAPoll selector can never produce.readEOF. WSAPoll has noPOLLRDHUPequivalent, soPOLLHUPis its only hangup signal and it fires for both an orderly peer FIN and an abortive RST.SelectorWSAPollmaps it to.reset, whichSelectableEventLoop.handleEventtreats as terminal, so a peer's orderly FIN tears down a live channel that had deliberately half-closed its input.Observed effect: the streamed-body failures in hummingbird-project/hummingbird#747 (tracked in #3697), and four
NIOSSLIntegrationTestclose-mode failures blocking Windows validation of apple/swift-nio-ssl#567. Instrumentation on a windows-2022 runner showed 8POLLHUPdeliveries of which 4 force-closed an open, active channel (socketOpen=true active=true); channels were registering interest in.readEOF(interestedRawincludes it) that the selector could never deliver. Not a duplicate of #3702: measured identical with and without the #3704 data-path fix.Modifications
Map
POLLHUPto.readEOFinstead of.resetinSelectorEventSet.init(wsaPollEvents:), with a comment explaining why. This mirrors what epoll does withEPOLLRDHUPand makesrecvthe authority on what actually happened: 0 bytes = orderly FIN (half-closure honoured when the channel allows it);WSAECONNRESET/WSAECONNABORTED= genuine abort, closed with the real error. One functional line.Result
Measured on windows-2022 / Swift 6.3.3:
testHalfCloseOwnOutputgoes from failing to passing; no new failures in the half-closure test runs.NIOSSLIntegrationTestfailures on Add support for Windows swift-nio-ssl#567 all pass; that PR's full suite is green with this change (plus one Windows path-separator fix in a test regex on the nio-ssl side).Also validated stacked on #3704 (the two changes are in different areas and compose).
One caveat worth stating: Windows half-closure has no upstream CI guard today because
StreamChannelTestis skipped on Windows (NIOPosixhas noPipeChannelthere), which is how this could ship undetected. We patched the harness to TCP-only on a probe branch to run the half-closure tests; a durable Windows guard likely wants that or aPipeChannelimplementation, which is beyond this PR.