Skip to content

preventing hang when TCPSocket readable, but no app-data is available#232

Open
dotconfig404 wants to merge 1 commit into
ruby:masterfrom
dotconfig404:patch-1
Open

preventing hang when TCPSocket readable, but no app-data is available#232
dotconfig404 wants to merge 1 commit into
ruby:masterfrom
dotconfig404:patch-1

Conversation

@dotconfig404

Copy link
Copy Markdown

eof? is a blocking read that times out when no application data is available - it should not be used as a readiness probe

@dotconfig404

Copy link
Copy Markdown
Author

fixes #233

Comment thread lib/net/http.rb
@dotconfig404 dotconfig404 force-pushed the patch-1 branch 2 times, most recently from 9aa8dce to 9e82856 Compare November 11, 2025 08:33
@rhenium rhenium requested a review from nurse November 11, 2025 09:51
Comment thread lib/net/http.rb Outdated
@socket.close
connect
elsif @socket.io.to_io.wait_readable(0) && @socket.eof?
elsif @socket.io.to_io.wait_readable(0) && @socket.io.read_nonblock(1, exception: false).nil?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The direction of this fix is correct. But this fix has a problem.
If this read_nonblock doesn't return a byte, it works as expected. But if it returns a byte, it needs to go forward but the byte is dropped in this patch. The byte needs to be buffered and re-used in actual process

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I see your point, although it shouldn't ever happen that a byte is returned, this is not the best way.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi again, does the new version look better?

It pushes back the byte should there really be a byte returned using ungetc to @rbuffer in OpenSSL::Buffering

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondereing if this PR could be revisted @nurse

@dotconfig404 dotconfig404 force-pushed the patch-1 branch 2 times, most recently from 743344b to 53d145a Compare March 6, 2026 13:08
@dotconfig404

Copy link
Copy Markdown
Author

i force-pushed a new version. it alters the way the existing code reviews look like now, so maybe that was wrong. hope it's ok, otherwise ill be happy to close and create a new PR. would like some quick feedback on what is preferred in this case.

@rhenium rhenium left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ungetc seems like a much simpler solution.

I think the EOFError branch can be removed, but otherwise this looks good to me.

Comment thread lib/net/http.rb
Comment on lines +2548 to +2549
rescue EOFError
true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this EOFError branch is unreachable.

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.

3 participants