Skip to content

Apply the request deadline to the TCP connect - #157

Open
hsbt wants to merge 1 commit into
masterfrom
claude/dreamy-lehmann-ed0812
Open

hsbt wants to merge 1 commit into
masterfrom
claude/dreamy-lehmann-ed0812

Conversation

@hsbt

@hsbt hsbt commented Oct 8, 2026

Copy link
Copy Markdown
Member

When a UDP reply comes back truncated, resolv retries the same nameserver over TCP, but that connect had no timeout. Against a nameserver that never completes the handshake, getaddress with timeouts = 1 waited about 135 seconds on Linux and then raised IO::TimeoutError (Ruby 4.0.6) instead of trying the next nameserver.

The connect now spends from the same interval as the request that follows it, and a timed out connect is handled like a refused one. I used Addrinfo#connect(timeout:) because TCPSocket.new accepts connect_timeout: only since Ruby 3.0.

The new tests fill the listener's accept queue so that Linux drops the SYN. Where the kernel completes or refuses such a connect instead, as macOS does, the tests are omitted.

Generated with Claude Code

Retrying a truncated reply over TCP connected with no timeout, so a nameserver that never completed the handshake held the query until the kernel gave up, regardless of `timeouts=`, and the resulting error escaped instead of moving on to the next nameserver. The connect now spends from the same interval as the request that follows it.

`Addrinfo#connect` is used because `TCPSocket.new` accepts `connect_timeout:` only since Ruby 3.0, and it raises `Errno::ETIMEDOUT` on every supported version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant