-
Notifications
You must be signed in to change notification settings - Fork 3.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
sql: run planHooks in a new tracing span #76084
Conversation
For some reason, plan hooks run in a new goroutine; that goroutine communicates results through a channel, that's adapted to look like a planNode by the hookFnNode. Before this patch, that goroutine was capturing the caller's ctx, and hence the caller's tracing span. This was leading to span-use-after-Finish because the goroutine in question was sometimes outliving the caller. Although not written anywhere, I think the expectation is that generally the goroutine will not outlive the the hookFnNode by much, since hookFnNode.Next() is supposed to be consumed fully. Still, at the very least, there were races related to ctx cancellation, as the hookFnNode listens for cancellation in parallel with the goroutine running (which is probably a bad idea). This patch fixes ths span use-after-finish by giving the goroutine a new span. I took the opportunity to give all the plan hooks names, and use that as the span name. Since these hooks are all weirdos, it seems like a good idea to particularly reflect them in the trace, regardless of the bug that's being fixed. Fixes cockroachdb#75425 Release note: None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! It's definitely a better approach than deriving a separate tracing span whenever a new "child" DistSQL flow is spun up.
Reviewed 11 of 11 files at r1, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @samiskin)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+ |
Build succeeded: |
For some reason, plan hooks run in a new goroutine; that goroutine
communicates results through a channel, that's adapted to look like a
planNode by the hookFnNode. Before this patch, that goroutine was
capturing the caller's ctx, and hence the caller's tracing span. This
was leading to span-use-after-Finish because the goroutine in question
was sometimes outliving the caller. Although not written anywhere, I
think the expectation is that generally the goroutine will not outlive
the the hookFnNode by much, since hookFnNode.Next() is supposed to be
consumed fully. Still, at the very least, there were races related to
ctx cancellation, as the hookFnNode listens for cancellation in parallel
with the goroutine running (which is probably a bad idea).
This patch fixes ths span use-after-finish by giving the goroutine a new
span. I took the opportunity to give all the plan hooks names, and use
that as the span name. Since these hooks are all weirdos, it seems like
a good idea to particularly reflect them in the trace, regardless of the
bug that's being fixed.
Fixes #75425
Release note: None