-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Request context is overridden in instrumented http clients #580
Comments
Thanks for the report. I assume this is only an issue with the |
beorn7
added a commit
that referenced
this issue
May 16, 2019
Fixes #580 Signed-off-by: beorn7 <bjoern@rabenste.in>
beorn7
added a commit
that referenced
this issue
May 16, 2019
Signed-off-by: beorn7 <bjoern@rabenste.in>
beorn7
added a commit
that referenced
this issue
May 16, 2019
Fixes #580 Signed-off-by: beorn7 <bjoern@rabenste.in>
beorn7
added a commit
that referenced
this issue
May 16, 2019
Fixes #580 Signed-off-by: beorn7 <bjoern@rabenste.in>
beorn7
added a commit
that referenced
this issue
May 16, 2019
Fixes #580 Signed-off-by: beorn7 <bjoern@rabenste.in>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is quite common for golang http clients to make use of the
context
package. Example use cases are to halt stalled requests or shutdown appropriately for example. When an application uses thegit.luolix.top/prometheus/client_golang/prometheus
package to instrument an http client for metrics, it expects the transport wrappers to preserve the behavior and state of the wrapped client.However, what happens with a request context set before the instrumentation of the client is that it gets replaced by the default root context and that makes quite of a difference:
From the golang docs:
"WithContext returns a shallow copy of r with its context changed to ctx."
The effect is that if you created a context with, for example,
context.WithTimeout
and set it to ahttp.Client
(client.WithContext(ctx)
), and then instrument the client, for example as suggested here, and then send requests to a server that is slow enough to trigger timeout, the timeout will never occur.What is expected instead is that the
InstrumentRoundTripperTrace
function respects existing request context, if any.All findings are wrt
v0.9.2
andmaster
.The text was updated successfully, but these errors were encountered: