-
Notifications
You must be signed in to change notification settings - Fork 436
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
[BUG] contrib/database/sql: Context passed to PrepareContext is used in later queries #2172
Labels
bug
unintended behavior that has to be fixed
Comments
3 tasks
nsrip-dd
added a commit
that referenced
this issue
Aug 14, 2023
The context used to prepare a statement and the context used to execute a statement need not be the same (see https://pkg.go.dev/database/sql#DB.PrepareContext) The execution trace task changes added in #2060 incorrectly used the statement's context from preparation to derive the execution trace task. We should be using the context provided for executing the statement instead. Fixes #2172
Thank you for the report, and for the reproducer! I've sent #2173 to address this. |
nsrip-dd
added a commit
that referenced
this issue
Aug 14, 2023
…ts (#2173) The context used to prepare a statement and the context used to execute a statement need not be the same (see https://pkg.go.dev/database/sql#DB.PrepareContext) The execution trace task changes added in #2060 incorrectly used the statement's context from preparation to derive the execution trace task. We should be using the context provided for executing the statement instead. Fixes #2172
ajgajg1134
pushed a commit
that referenced
this issue
Sep 5, 2023
…ts (#2173) The context used to prepare a statement and the context used to execute a statement need not be the same (see https://pkg.go.dev/database/sql#DB.PrepareContext) The execution trace task changes added in #2060 incorrectly used the statement's context from preparation to derive the execution trace task. We should be using the context provided for executing the statement instead. Fixes #2172
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version of dd-trace-go
v1.54.0
Describe what happened:
Context passed to
db.PrepareContext()
is kept throughout the lifespan of stmt, yielding "context canceled" error when using the stmt after the context is canceled.The following code shadows
ctx
with a context derived froms.ctx
, which is already canceled.dd-trace-go/contrib/database/sql/stmt.go
Lines 62 to 65 in 30bfd52
Go documentation states that
The provided context is used for the preparation of the statement, not for the execution of the statement.
Describe what you expected:
Context used in
PrepareContext
is not preserved; returned Stmt should be usable even after the prepare context has been expired.Steps to reproduce the issue:
Code to reproduce: (actual driver implementation does not matter, tested MySQL and SQLite)
When using
connectSQLiteNoTrace()
, the result prints out correctly. However, when usingconnectSQLite()
, it returns "context canceled" error onQueryRowContext
.Additional environment details (Version of Go, Operating System, etc.):
Tested on go1.20.5 darwin/arm64, but OS shouldn't matter.
The text was updated successfully, but these errors were encountered: