-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix unix socket half-close handling in Sockets #60961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ea5902f
7b867be
0092f5c
8e89606
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -665,75 +665,55 @@ end | |
| function uv_readcb(handle::Ptr{Cvoid}, nread::Cssize_t, buf::Ptr{Cvoid}) | ||
| 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) | ||
| lock(stream.cond) | ||
| if nread < 0 | ||
| if nread == UV_ENOBUFS && nrequested == 0 | ||
| # remind the client that stream.buffer is full | ||
| notify(stream.cond) | ||
| elseif nread == UV_EOF # libuv called uv_stop_reading already | ||
| if stream.status != StatusClosing | ||
| stream.status = StatusEOF | ||
| try | ||
| if nread < 0 | ||
| if nread == UV_ENOBUFS && nrequested == 0 | ||
| # remind the client that stream.buffer is full | ||
| notify(stream.cond) | ||
| if stream isa TTY | ||
| # stream can still be used by reseteof (or possibly write) | ||
| elseif !(stream isa PipeEndpoint) && ccall(:uv_is_writable, Cint, (Ptr{Cvoid},), stream.handle) != 0 | ||
| # stream can still be used by write | ||
| else | ||
| # underlying stream is no longer useful: begin finalization | ||
| ccall(:jl_close_uv, Cvoid, (Ptr{Cvoid},), stream.handle) | ||
| stream.status = StatusClosing | ||
| elseif nread == UV_EOF | ||
| if stream.status != StatusClosing | ||
| stream.status = StatusEOF | ||
| notify(stream.cond) | ||
|
|
||
| if stream isa TTY | ||
| # still usable | ||
| elseif !(stream isa PipeEndpoint) && | ||
| ccall(:uv_is_writable, Cint, (Ptr{Cvoid},), stream.handle) != 0 | ||
| # still writable | ||
| else | ||
| ccall(:jl_close_uv, Cvoid, (Ptr{Cvoid},), stream.handle) | ||
| stream.status = StatusClosing | ||
| end | ||
| end | ||
| else | ||
| stream.readerror = _UVError("read", nread) | ||
| notify(stream.cond) | ||
| ccall(:jl_close_uv, Cvoid, (Ptr{Cvoid},), stream.handle) | ||
| stream.status = StatusClosing | ||
| end | ||
| else | ||
| stream.readerror = _UVError("read", nread) | ||
| notify_filled(stream.buffer, nread) | ||
| notify(stream.cond) | ||
| # This is a fatal connection error | ||
| ccall(:jl_close_uv, Cvoid, (Ptr{Cvoid},), stream.handle) | ||
| stream.status = StatusClosing | ||
| end | ||
| else | ||
| notify_filled(stream.buffer, nread) | ||
| notify(stream.cond) | ||
| finally | ||
| unlock(stream.cond) | ||
| end | ||
| unlock(stream.cond) | ||
|
|
||
| # Stop background reading when | ||
| # 1) there's nobody paying attention to the data we are reading | ||
| # 2) we have accumulated a lot of unread data OR | ||
| # 3) we have an alternate buffer that has reached its limit. | ||
| if stream.status == StatusPaused || | ||
| (stream.status == StatusActive && | ||
| ((bytesavailable(stream.buffer) >= stream.throttle) || | ||
| (bytesavailable(stream.buffer) >= stream.buffer.maxsize))) | ||
| # save cycles by stopping kernel notifications from arriving | ||
| ccall(:uv_read_stop, Cint, (Ptr{Cvoid},), stream) | ||
| stream.status = StatusOpen | ||
| end | ||
| nothing | ||
| end | ||
| readcb_specialized(stream_unknown_type, Int(nread), UInt(nrequested)) | ||
| nothing | ||
| end | ||
|
|
||
| function reseteof(x::TTY) | ||
| iolock_begin() | ||
| if x.status == StatusEOF | ||
| x.status = StatusOpen | ||
| nothing | ||
| end | ||
| iolock_end() | ||
|
Comment on lines
-719
to
-724
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mistakenly removed the TTY fucntion |
||
| nothing | ||
| end | ||
|
|
||
| function _uv_hook_close(uv::Union{LibuvStream, LibuvServer}) | ||
| lock(uv.cond) | ||
| try | ||
| uv.status = StatusClosed | ||
| # notify any listeners that exist on this libuv stream type | ||
| notify(uv.cond) | ||
| finally | ||
| unlock(uv.cond) | ||
| end | ||
| readcb_specialized(stream_unknown_type, Int(nread), UInt(nrequested)) | ||
| nothing | ||
| end | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabling "Hide whitespace" in the GitHub diff viewer, it seems to me that the changes to this function amount to:
try/finally/endwithunlockin the finalize block -- that seems plausible;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! )