Skip to content

Commit

Permalink
fix: dns outbound udp timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Apr 9, 2024
1 parent bd703b8 commit de38fa8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions adapter/outbound/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ func (d *dnsPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
return len(p), nil
}

ctx, cancel := context.WithTimeout(d.ctx, resolver.DefaultDnsRelayTimeout)
defer cancel()

buf := pool.Get(resolver.SafeDnsPacketSize)
put := func() { _ = pool.Put(buf) }
copy(buf, p) // avoid p be changed after WriteTo returned

go func() { // don't block the WriteTo function
ctx, cancel := context.WithTimeout(d.ctx, resolver.DefaultDnsRelayTimeout)
defer cancel()

buf, err = resolver.RelayDnsPacket(ctx, buf[:len(p)], buf)
if err != nil {
put()
Expand Down

0 comments on commit de38fa8

Please sign in to comment.