-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
net/http/httptrace: attaching a ClientTrace twice to the same context causes stack overflow #32925
Comments
I'm surprised looking at the code that |
CC @bradfitz, but note that he's unavailable for a while. Note that the same failure mode can occur with any number of intervening traces, so it's not just a matter of checking whether |
I don't know why yet, but the error does not come to happen if the copy of tfCopy := reflect.ValueOf(tf.Interface())
ofCopy := reflect.ValueOf(of.Interface())
// We need to call both tf and of in some order.
newFunc := reflect.MakeFunc(hookType, func(args []reflect.Value) []reflect.Value {
tfCopy.Call(args)
return ofCopy.Call(args)
}) The output is still strange but like the below.
|
Change https://golang.org/cl/186217 mentions this issue: |
I proposed a solution. Please, review it if possible: https://go-review.googlesource.com/c/go/+/186217. @tomocy, making also a copy of old hook function would solve the recursive cycle and then the stack overflow. But it won't fix the inconsistency of number of times a given hook function will be called. Let's take a look at below test function.
If I register
This is inconsistency is due to the fact that The solution in this case is let |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
What did you expect to see?
"traced" gets printed twice, and then a request error because nothing is listening on localhost:9999.
What did you see instead?
The stack overflows.
What I'm doing is silly, but it happened in production for a service due to a lot of indirection on retries and attempting to use a single tracer object for all traces.
The bug seems to be here
go/src/net/http/httptrace/trace.go
Lines 202 to 204 in b412fde
Since
*t
and*old
are the same, theof.Call()
ends up calling itself.The text was updated successfully, but these errors were encountered: