Bug Description
In context_cancel.go, the cancel() function from context.WithTimeout is not deferred, so if client.Exchange panics (e.g., due to a nil pointer in the DNS library), the context resources (timer goroutine) will leak until the timeout fires.
Affected Code
resolve.go:59-61:
ctx, cancel := context.WithTimeout(context.Background(), readTimeout)
response, rtt, err := client.Exchange(ctx, msg, "udp", server)
cancel()
Note that other parts of the codebase (e.g., xtransport.go:483, plugin_dns64.go:205) correctly use defer cancel().
Impact
If client.Exchange panics, cancel() is never called, causing a context/timer leak. While rare, this is a correctness issue.
Fix
ctx, cancel := context.WithTimeout(context.Background(), readTimeout)
defer cancel()
response, rtt, err := client.Exchange(ctx, msg, "udp", server)
Bug Description
In
context_cancel.go, thecancel()function fromcontext.WithTimeoutis not deferred, so ifclient.Exchangepanics (e.g., due to a nil pointer in the DNS library), the context resources (timer goroutine) will leak until the timeout fires.Affected Code
resolve.go:59-61:Note that other parts of the codebase (e.g.,
xtransport.go:483,plugin_dns64.go:205) correctly usedefer cancel().Impact
If
client.Exchangepanics,cancel()is never called, causing a context/timer leak. While rare, this is a correctness issue.Fix