Skip to content

Return nil from recv_nonblock at EOF and raise its other errors - #10218

Open
CufeHaco wants to merge 1 commit into
jruby:masterfrom
CufeHaco:recv-nonblock-eof
Open

CufeHaco wants to merge 1 commit into
jruby:masterfrom
CufeHaco:recv-nonblock-eof

Conversation

@CufeHaco

@CufeHaco CufeHaco commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Split out of #9874, as Sampo asked.

BasicSocket#recv_nonblock raised EAGAIN forever once the peer had shut down, instead of returning nil the way CRuby does, because "no data yet" and EOF looked the same. The nonblocking read now keeps the raw count, so EOF is reported separately from "would block".

exception: false also hid every error, not just "would block". That meant a connected but unbound socket returned nil instead of raising Errno::ENOTCONN. Now it only silences "would block". On a DatagramChannel, a zero-length datagram is now data ("") rather than EAGAIN, and the channel's blocking mode is restored afterwards.

This untags 3 specs in recv_nonblock_tags.txt: EOF on a closed stream socket, and ENOTCONN ×2.

Testing: the EOF spec hangs on master, passes with this change, and passes on CRuby 4.0. The rest of spec/ruby/library/socket shows no new failures.

BasicSocket#recv_nonblock treated "no data yet" and EOF the same, so once
the peer had shut down it raised EAGAIN forever instead of returning nil
as CRuby does. The nonblocking read now keeps the raw count, and EOF is
reported apart from "would block".

exception: false hid every error, not only "would block", so a connected
but unbound socket returned nil instead of raising Errno::ENOTCONN. Now
it only silences "would block". For a DatagramChannel, a zero-length
datagram is data ("") rather than EAGAIN, read_nonblock reads it as EOF
as CRuby does, and the channel's blocking mode is put back afterwards.

Untags the recv_nonblock specs for EOF on a closed stream socket and for
ENOTCONN on a connected but unbound socket.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants