Conversation
- Don't do premature write shutdown (SHUT_WR) on the socket used to read the stdin data (aka socket_r). - Remove broken setsockopt call for SO_DONTLINGER on socket_r. - Treat ReadFile receiving 0 bytes as valid (it seems this is allowed). Prior to this change a partial shutdown of the write side of the read socket that the main thread reads stdin data from (socket_r) happened before reading the data from the socket. The partial shutdown caused a FIN to be sent which lingered for ~2 minutes (typical OS configured time), and after that time the connection was terminated. Theory of operation to read stdin on windows is a connection is established to relay stdin from a dedicated thread (write to socket_w) to the main thread (read from socket_r) so reading stdin is non-blocking. Data truncation would occur if this process was not completed by the linger time. Ref: curl#22383 (comment) Closes #xxxx
- wait for all data to be received by the main thread
Prior to this change treating 0 bytes as valid and not eof caused test 1498 (upload arbitrary data from stdin) to hang in mingw CI jobs.
we need to call recv on this socket and wait for shutdown.
the wait time on shutdown and recv is not controllable by LINGER wait time which is exclusively used by closesocket
jay
marked this pull request as ready for review
August 30, 2026 07:45
Member
Author
|
Can someone take a look at this so I can land it before the release? |
There was a problem hiding this comment.
🟢 Approval recommended
Pull request overview
Fixes Windows asynchronous stdin relay truncation by correcting socket shutdown sequencing.
Changes:
- Removes premature half-shutdowns and invalid
SO_DONTLINGERusage. - Sends FIN after stdin EOF and waits for the receiving socket to close.
- Documents observed Windows pipe EOF behavior.
File summaries
| File | Description |
|---|---|
src/tool_doswin.c |
Corrects Windows stdin relay socket lifecycle and EOF handling. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Don't do premature write shutdown (SHUT_WR) on the socket used to read the stdin data (aka socket_r).
Don't do premature read shutdown (SHUT_RD) on the socket used to write the stdin data (aka socket_w).
Remove broken setsockopt call for SO_DONTLINGER on socket_r.
Treat ReadFile receiving 0 bytes as valid (it seems this is allowed).(removed because mingw uses it to signal eof)Wait until all data sent from socket_w is acknowledged by socket_r.
Prior to this change a partial shutdown of the write side of the read socket that the main thread reads stdin data from (socket_r) happened before reading the data from the socket. The partial shutdown caused a FIN to be sent which lingered for ~2 minutes (typical OS configured time), and after that time the connection was terminated.
Theory of operation to read stdin on windows is a connection is established to relay stdin from a dedicated thread (write to socket_w) to the main thread (read from socket_r) so reading stdin is non-blocking. Data truncation would occur if this process was not completed by the OS FIN reply wait time.
Ref: #22383 (comment)
Closes #xxxx
/cc @11soda11 @denandz