diff --git a/client.go b/client.go index cd60cf8..1475687 100644 --- a/client.go +++ b/client.go @@ -19,7 +19,7 @@ import ( const ( DefaultTTL = 600 - DefaultTimeout = 5 * time.Second + DefaultTimeout = 10 * time.Second ) var ( @@ -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 } @@ -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) }