-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
canceling deadline context not honored #1399
Comments
The root cause for this is Another issue this causes is It also means that when a timeout occurs, I think that unfortunately doing a proper fix for this would need a change to Go's standard library since we need A less ideal fix that might be acceptable is to wrap the IO in a goroutine that we leave running in the background if the context ends before the exchange completes: func (c *Client) ExchangeWithConnContext(ctx context.Context, m *Msg, co *Conn) (r *Msg, rtt time.Duration, err error) {
type result struct {
r *Msg
rtt time.Duration
err error
}
ch := make(chan result, 1) // 1: prevent the sender from blocking forever ctx ended first
go func() {
defer close(ch)
r, rtt, err := c.exchangeWithConnContext(ctx, m, co) // this would be the existing ExchangeWithConnContext
ch <- result{r, rtt, err}
}()
select {
case res := <-ch:
return res.r, res.rtt, res.err
case <-ctx.Done():
return nil, 0, ctx.Err()
}
} The good news is this can be done as a workaround outside of this module :) @miekg would you be open to merging such a fix? |
When providing a deadline context to Client.ExchangeContext(), canceling is only honored during the dial stage but not during the read or write stage.
The text was updated successfully, but these errors were encountered: