Skip to content

Commit

Permalink
sql: prevent span use after finish with rollbacks and high vmodule
Browse files Browse the repository at this point in the history
Previously, we could get a panic of "span use after finish" in test
builds in some cases (like a rollback). This was occurring since the
context cancellation function can log some stuff depending on the
verbosity level (in `contextutil/context.go:74`) long time after we have
finished the tracing span from that context. To go around that issue we
now push the responsibility of finishing the span into the cancellation
function.

Release note: None
  • Loading branch information
yuzefovich committed Jul 18, 2022
1 parent 7191d81 commit 39b7178
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2285,9 +2285,17 @@ func (st *SessionTracing) StartTracing(
if sp == nil {
return errors.Errorf("no txn span for SessionTracing")
}
// We're hijacking this span and we're never going to un-hijack it, so it's
// up to us to finish it.
sp.Finish()
// Since we're hijacking this span and we're never going to un-hijack
// it, it's up to us to make sure it is finished somehow. Unfortunately,
// we cannot just finish it right away because in some cases the span
// will be used later (if the verbosity is high enough, during the
// context cancellation). To go around that, we pass the responsibility
// of finishing the span to the cancellation function.
cancelTxnCtx := st.ex.state.cancel
st.ex.state.cancel = func() {
cancelTxnCtx()
sp.Finish()
}

st.ex.state.Ctx, _ = tracing.EnsureChildSpan(
newConnCtx, st.ex.server.cfg.AmbientCtx.Tracer, "session tracing")
Expand Down

0 comments on commit 39b7178

Please sign in to comment.