Open vbqz opened 1 year ago
_, err = db.ExecContext(ctx, "select sqlite_version();")
If db.ExecContext is an async method, xray sdk would create subsegment after the parent segment closed, then cause xray context missing panic.
Alternatively we recommend user move to opentelemetry, that SDK supports asynchronous better, has no context missing error.
Hi,
My team bumped into
failed to begin subsegment
panics when usingSQLContext
together with setting limits on connection numbers and durations.With
aws-xray-sdk-go v1.8.0
the problem still occurs, but logs instead of panics (which is great!). But I wanted to check if we are misusing the SDK in anyway, and give you a heads up if there is some kind of race condition here.Issue
When using a database connection created like:
Executing queries with instrumented contexts occasionally caused panics like:
From what I can tell, there is a small chance that
database/sql
will try to open a fresh conn usingcontext.Background()
, instead of using the caller context, or re-using an existing connection.Reprod
I managed to come up with this slightly contrived program (tons of connections and very low lifetimes) that reliably triggers the failure on my machine:
The stacktrace at the failed subsegment is:
So its the
connectionOpener
goroutine that gets a request for another connection, and tries to do it withcontext.Background()
.