Skip to content

Apply the request timeout to the TCP connect - #161

Open
mame wants to merge 1 commit into
ruby:masterfrom
mame:tcp-connect-timeout
Open

mame wants to merge 1 commit into
ruby:masterfrom
mame:tcp-connect-timeout

Conversation

@mame

@mame mame commented Oct 24, 2026

Copy link
Copy Markdown
Member

The TCP fallback after a truncated reply connected with no time limit, so a nameserver dropping SYNs blocked for the OS connect timeout and raised IO::TimeoutError. Bound the connect by the timeout and treat a timed out connect like a refused one, moving on to the next nameserver.

Reported by: irevivalx (https://hackerone.com/irevivalx)

The TCP fallback after a truncated reply connected with no time limit,
so a nameserver dropping SYNs blocked for the OS connect timeout and
raised IO::TimeoutError. Bound the connect by the timeout and treat a
timed out connect like a refused one, moving on to the next nameserver.

Reported by: irevivalx (https://hackerone.com/irevivalx)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mame
mame requested review from akr, nobu and shioimm October 24, 2026 07:59
Comment thread lib/resolv.rb
@port = port
sock = TCPSocket.new(@host, @port)
sock = if connect_timeout && RUBY_VERSION >= "3.0"
TCPSocket.new(@host, @port, connect_timeout: connect_timeout)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On Ruby 4.0 and later, open_timeout is available, which times out based on the time elapsed since the start of the method call.
However, for the purpose of this change, I think it's fine to keep connect_timeout, which times out based on the time elapsed since the start of the last connection attempt.

This branch has not been deployed

No deployments
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