Skip to content

Commit

Permalink
Fix timeout not apply to lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jun 24, 2024
1 parent 10a16e0 commit b1625ab
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const (
DefaultTTL = 600
DefaultTimeout = 5 * time.Second
DefaultTimeout = 10 * time.Second
)

var (
Expand Down Expand Up @@ -158,14 +158,9 @@ func (c *Client) ExchangeWithResponseCheck(ctx context.Context, transport Transp
return nil, ErrResponseRejectedCached
}
}
var cancel context.CancelFunc
if c.timeout > 0 {
ctx, cancel = context.WithTimeout(ctx, c.timeout)
}
ctx, cancel := context.WithTimeout(ctx, c.timeout)
response, err := transport.Exchange(ctx, message)
if cancel != nil {
cancel()
}
cancel()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -306,8 +301,10 @@ func (c *Client) LookupWithResponseCheck(ctx context.Context, transport Transpor
return nil, ErrResponseRejectedCached
}
}
ctx, cancel := context.WithTimeout(ctx, c.timeout)
var rCode int
response, err := transport.Lookup(ctx, domain, strategy)
cancel()
if err != nil {
return nil, wrapError(err)
}
Expand Down

0 comments on commit b1625ab

Please sign in to comment.