Fix unix socket half-close handling in Sockets#60961
Fix unix socket half-close handling in Sockets#60961abslock128w wants to merge 4 commits intoJuliaLang:masterfrom
Conversation
Added tests for Unix domain socket half-close behavior.
Removed unnecessary checks for TTY and PipeEndpoint in EOF handling.
Handle stream closure for PipeEndpoint in UV_EOF case.
|
Ref: #60959 @abslock128w apologies if this is unfounded, but I get the sense that LLMs may have been used in formulating this PR. If this is the case, we would appreciate it if you would declare this. |
yeah I did use an LLM a bit while working on this, used it to understand the already writtne code |
| stream_unknown_type = @handle_as handle LibuvStream | ||
| nrequested = ccall(:jl_uv_buf_len, Csize_t, (Ptr{Cvoid},), buf) | ||
|
|
||
| function readcb_specialized(stream::LibuvStream, nread::Int, nrequested::UInt) |
There was a problem hiding this comment.
Enabling "Hide whitespace" in the GitHub diff viewer, it seems to me that the changes to this function amount to:
- wrapping most of the code into a
try/finally/endwithunlockin the finalize block -- that seems plausible; - inserting some empty lines, wrapping an overly long line -- I am neutral on this;
- removing or reducing a lot of comments -- that part seems less plausible: why do we want to remove comments or reduce them? Were they incorrect?
There was a problem hiding this comment.
Hey there,
Thank you for pointing out the mistake!
I am new to this whole open source contribution thing...
And about the comment part I never really use comments that's wrong on my part ( i know its a good practice to do so,
will try to keep that in mind as I move forward! )
| function reseteof(x::TTY) | ||
| iolock_begin() | ||
| if x.status == StatusEOF | ||
| x.status = StatusOpen | ||
| nothing | ||
| end | ||
| iolock_end() |
There was a problem hiding this comment.
Why is reseteof(x::TTY) being removed?
There was a problem hiding this comment.
I mistakenly removed the TTY fucntion
This will probably brake the interactive input...
Will add in the next commit.
Again thank you for pointing it out!
Summary
Fix incorrect handling of unix domain socket half-close where a
PipeEndpointwas fully closed onUV_EOF, even when the write sidewas still usable.
Problem
When libuv reports
UV_EOF, Julia currently finalizes certainLibuvStreams (notablyPipeEndpoint) too aggressively.This breaks valid half-close semantics, where the read side reaches EOF but the socket remains writable.
This behavior causes issues in clients that rely on
half-closed unix sockets, forcing workarounds such as splitting stdio
into multiple sockets.
Solution
Update
uv_readcbto preserve the stream when the underlying handleremains writable, allowing correct half-close behavior while still
closing truly unusable streams.
The change aligns Julia’s behavior with libuv semantics and POSIX
expectations.