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 f00a9b6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/resolvers/doq.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (r *DOQResolver) query(ctx context.Context, question dns.Question, flags Qu
if err != nil {
return rsp, err
}
defer stream.Close()

msgLen := uint16(len(b))
msgLenBytes := []byte{byte(msgLen >> 8), byte(msgLen & 0xFF)}
Expand All @@ -84,6 +83,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 f00a9b6

Please sign in to comment.