Skip to content

fix: avoid 20s DNS timeout blocking UDP packet connections#239

Merged
myleshorton merged 3 commits intomainfrom
fix/packet-conn-dns-timeout
Apr 15, 2026
Merged

fix: avoid 20s DNS timeout blocking UDP packet connections#239
myleshorton merged 3 commits intomainfrom
fix/packet-conn-dns-timeout

Conversation

@myleshorton
Copy link
Copy Markdown
Contributor

@myleshorton myleshorton commented Apr 14, 2026

Summary

  • sendInfo() for UDP packet connections was calling net.ResolveUDPAddr() to resolve the destination hostname on every new connection
  • The routing pipeline already resolves destinations into metadata.DestinationAddresses — this second lookup is redundant
  • Remove it and use the pre-resolved addresses directly

Test plan

  • TestSendInfoWithIPDestination — IP destination still works
  • TestSendInfoWithDomainAndResolvedAddresses — domain with pre-resolved addresses uses them directly
  • TestSendInfoWithDomainNoResolvedAddresses — domain without resolved addresses returns clear error

Diagnosed from Freshdesk #172590.

🤖 Generated with Claude Code

…0s DNS timeout

sendInfo() for UDP packet connections was calling net.ResolveUDPAddr()
to resolve the destination hostname synchronously. In fakeip mode, the
system DNS points at the TUN address (10.10.1.2:53), so the resolution
re-enters sing-box and stalls for 20 seconds before timing out. This
blocks the entire packet connection — no data flows until the timeout
completes, then the connection is killed.

The routing pipeline already resolves destinations into
metadata.DestinationAddresses earlier in the flow. Use those instead
of re-resolving.

Diagnosed from Freshdesk #172590 (internal user reporting slow/inconsistent
connection). Every new UDP/QUIC connection was blocked for 20s by this path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 14, 2026 22:17
@myleshorton myleshorton requested a review from garmr-ulfr April 14, 2026 22:18
… the timeout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes UDP/QUIC packet connections stalling for ~20 seconds in fakeip mode by removing a synchronous DNS resolution step (net.ResolveUDPAddr) from the client-context injection path and instead using addresses already resolved by the routing pipeline (metadata.DestinationAddresses).

Changes:

  • Update UDP sendInfo() to use InboundContext.DestinationAddresses[0] for domain destinations instead of calling net.ResolveUDPAddr.
  • Add/adjust tests to cover: IP destinations, domain destinations with pre-resolved addresses, and domain destinations without resolved addresses (error case).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tracker/clientcontext/injector.go Avoids synchronous DNS resolution for UDP destinations by using DestinationAddresses and failing fast when not available.
tracker/clientcontext/injector_test.go Updates/adds unit tests to validate the new resolved-address behavior and the new error path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tracker/clientcontext/injector.go
Copy link
Copy Markdown
Collaborator

@garmr-ulfr garmr-ulfr left a comment

Choose a reason for hiding this comment

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

LGTM. Just one comment. I'm not sure if Copilot's comment is correct or not, but it really depends on whether we want to worry about IPv6. 🤷

Comment thread tracker/clientcontext/injector.go Outdated
… is empty

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@myleshorton myleshorton merged commit 88fe3fa into main Apr 15, 2026
3 checks passed
@myleshorton myleshorton deleted the fix/packet-conn-dns-timeout branch April 15, 2026 12:04
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