-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
database/sql: sqlboiler-using project fails with cancellation errors after context/RawBytes CL when many tests run #60932
Comments
Also CC @kardianos, @kevinburke via owners. |
Tentatively marking as a release-blocker since this is caused by a CL new in Go 1.21, and needs investigation. The release-blocker label can be removed if investigation shows this doesn't need to block the release. (Or, of course, the issue can be closed when the problem is resolved.) |
Some further investigation: If I wholesale replace my context with I'm hoping to recreate this from scratch in a new repo, but I unfortunately found this at a time when I'm less able to spend time working on it. |
Hm, so I have a theory (which I need to test):
|
Yeah, I think that the above is correct; I modified
Which implies that close should not be affecting I'm not totally sure if Testing out that fix locally does the trick, fixing my repro and still passing the existing |
Change https://go.dev/cl/505397 mentions this issue: |
I have mailed a CL which I believe fixes the issue. Happy to take feedback or have my CL superceded by a better one! |
… Rows.Err() CL 497675 modified Rows such that context errors are propagated through Rows.Err(). This caused an issue where calling Close meant that an internal cancellation error would (eventually) be returned from Err: 1. A caller makes a query using a cancellable context. 2. initContextClose sees that either the query context or the transaction context can be canceled, so will need to spawn a goroutine to capture their errors. 3. initContextClose derives a context from the query context via WithCancel and sets rs.cancel. 4. When a user calls Close, rs.cancel is called. awaitDone's ctx is cancelled, which is good, since we don't want it to hang forever. 5. This internal cancellation (after CL 497675) has its error saved on contextDone. 6. Later, calling Err will return the error in contextDone if present. This leads to a race condition depending on how quickly Err is called after Close. The docs for Close and Err state that calling Close should have no affect on the return result for Err. So, a potential fix is to ensure that awaitDone does not save the error when the cancellation comes from a Close via rs.cancel. This CL does that, using a new context not derived from the query context, whose error is ignored as the query context's error used to be before the original bugfix. The included test fails before the CL, and passes afterward. Fixes golang#60932 Change-Id: I2bf4c549efd83d62b86e298c9c45ebd06a3ad89a Reviewed-on: https://go-review.googlesource.com/c/go/+/505397 Auto-Submit: Russ Cox <[email protected]> Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
On tip.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I really have to apologize, I don't yet have a reproduction that's more minimal than my actual project. Testing this "only" requires
docker
running locally.go test ./internal/bot
What did you expect to see?
Tests pass.
What did you see instead?
After CL 497675 (I bisected to be sure), my tests appear to fail, with sqlboiler calls returning errors that mention context cancellation. Something like:
It's not one specific test either; it only happens when I run enough tests, e.g. run the whole thing. E.g.,
go test -run "TestScripts/quotes/add" ./internal/bot
will pass, butgotip test ./internal/bot
will fail.TestScripts/quotes
sometimes fails.I have tested with
-race
and don't see any races reported. Passing-parallel 1
also does not change things. I have also changed my postgres driver to another one, and see the same behavior.Again, apologies for such a big repro; I'm not quite sure where to start minimizing this.
cc @bradfitz
ref #60304 #53970
The text was updated successfully, but these errors were encountered: