Fix: Socket#accept
obeys read_timeout
#9538
Merged
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.
Currently if a
read_timeout
is used on aSocket
,accept_impl
will just keep looping until a connection is received. This was already noticed by @grioja on this comment. I refactored the internal implementation so it doesn't rely on exception handling.I was hesitant about making
accept?
to returnnil
in case of timeout. But there are currently parts of the code that assumes that if anil
is returned it's because the socket was closed. On the other hand this was the behaviour until #8707 was merged so that would be a breaking change to do in a separate PR if that's desired.