Skip to content

Commit

Permalink
add SetWriteDeadline (#358)
Browse files Browse the repository at this point in the history
* fix query-timeout for doq

* fix query-timeout for doq
  • Loading branch information
nickzhog committed Nov 14, 2023
1 parent 58b67ea commit 0cbc856
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions doqclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func NewDoQClient(id, endpoint string, opt DoQClientOptions) (*DoQClient, error)
tlsConfig: tlsConfig,
config: &quic.Config{
TokenStore: quic.NewLRUTokenStore(10, 10),
HandshakeIdleTimeout: opt.QueryTimeout,
},
},
metrics: NewListenerMetrics("client", id),
Expand Down Expand Up @@ -128,6 +129,8 @@ func (d *DoQClient) Resolve(q *dns.Msg, ci ClientInfo) (*dns.Msg, error) {
edns0.Option = newOpt
}

deadlineTime := time.Now().Add(d.DoQClientOptions.QueryTimeout)

// Encode the query
p, err := qc.Pack()
if err != nil {
Expand All @@ -148,7 +151,7 @@ func (d *DoQClient) Resolve(q *dns.Msg, ci ClientInfo) (*dns.Msg, error) {
}

// Write the query into the stream and close it. Only one stream per query/response
_ = stream.SetWriteDeadline(time.Now().Add(d.DoQClientOptions.QueryTimeout))
_ = stream.SetWriteDeadline(deadlineTime)
if _, err = stream.Write(b); err != nil {
d.metrics.err.Add("write", 1)
return nil, err
Expand All @@ -158,7 +161,7 @@ func (d *DoQClient) Resolve(q *dns.Msg, ci ClientInfo) (*dns.Msg, error) {
return nil, err
}

_ = stream.SetReadDeadline(time.Now().Add(d.DoQClientOptions.QueryTimeout))
_ = stream.SetReadDeadline(deadlineTime)

// DoQ requires a length prefix, like TCP
var length uint16
Expand Down

0 comments on commit 0cbc856

Please sign in to comment.