net/http: Transport.CancelRequest not always called if RoundTrip returns promptly when a request times out #34552
Comments
Why do you expect Per its documentation:
That seems to also imply that A version of your test program modified to do so (https://play.golang.org/p/7ZZRvEpy9uJ) seems to confirm that in all cases, either |
CC @bradfitz to confirm, but I'm pretty sure this is working as designed. An additional test confirms that |
Yup, looks like it's working fine. In the original snippet there was no need for net/http to call CancelRequest because Do had already failed in time. Thanks for investigating, @bcmills. |
Because the
@bcmills for context, I'm writing tracing middleware that wraps others' arbitrarily old and crusty code, harking back from from versions of Go that do not support context. I don't have much of a say about whether they use CancelRequest or Context cancellation. Perhaps the docs ought to be clarified? Then again, we've probably spent enough time in this dusty corner. I'll change my test to accommodate. Thanks both for looking into it. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The tests for my project,
go.elastic.co/apm
, started failing when running against go tip.I strongly suspect 7fc2625, since it started happening today. The issue can be reproduced with https://play.golang.org/p/MQepDRMdcjL
What did you expect to see?
The program should run and exit cleanly.
What did you see instead?
The program runs for ~10 seconds and panics, due to CancelRequest not being called.
Note that this doesn't happen every time, hence the loop. If I increase the timeout to 50ms it becomes less frequent, but still fails occasionally.
The text was updated successfully, but these errors were encountered: