Skip to content

Commit

Permalink
Fix slow DNS queries over quic
Browse files Browse the repository at this point in the history
We need to explicitly close the write stream otherwise we wait until the
timeout to read the response.

Signed-off-by: Sylvain Rabot <[email protected]>
  • Loading branch information
sylr committed Dec 16, 2024
1 parent 16ba284 commit 251275f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/resolvers/doq.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ func (r *DOQResolver) query(ctx context.Context, question dns.Question, flags Qu
return rsp, err
}

// The client MUST send the DNS query over the selected stream, and MUST
// indicate through the STREAM FIN mechanism that no further data will be
// sent on that stream. Note, that stream.Close() closes the write-direction
// of the stream, but does not prevent reading from it.
// See: https://github.com/AdguardTeam/dnsproxy/blob/f901a5f4b9e8d5f143dce459067bc6614c6d927d/upstream/doq.go#L247-L254
err = stream.Close()
if err != nil {
return rsp, fmt.Errorf("unable to close quic stream: %w", err)
}

// Use a separate context with timeout for reading the response
readCtx, cancel := context.WithTimeout(ctx, r.resolverOptions.Timeout)
defer cancel()
Expand Down

0 comments on commit 251275f

Please sign in to comment.