-
Notifications
You must be signed in to change notification settings - Fork 566
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
Find and fix more nested transactions #9942
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jrockway
force-pushed
the
jonathan/audit-txn
branch
from
April 11, 2024 18:49
078f36f
to
5581c51
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9942 +/- ##
==========================================
- Coverage 58.08% 58.04% -0.05%
==========================================
Files 611 611
Lines 74357 74354 -3
==========================================
- Hits 43191 43157 -34
- Misses 30614 30656 +42
+ Partials 552 541 -11 ☔ View full report in Codecov by Sentry. |
jrockway
force-pushed
the
jonathan/audit-txn
branch
from
April 11, 2024 19:09
5581c51
to
df300e9
Compare
robert-uhl
approved these changes
Apr 11, 2024
brendoncarroll
approved these changes
Apr 11, 2024
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.
LGTM
jrockway
added a commit
that referenced
this pull request
Apr 15, 2024
This removes a couple cases where WithReadContext is run inside WithTx, which ends up consuming 2 connections from the database connection pool in a way that can deadlock if there is only 1 connection available in the pool. This is sort of a backport of #9942, but without infrastructure/refactorings to detect nested transactions. This should be sufficient to eliminate any existing problems, as long as we don't add more code directly to this branch. Part of CORE-2246.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a DPANIC log message for WithTx calls that call WithTx, i.e. nesting database transactions. Nested database transactions are problematic because they can deadlock; if the first tx takes the last database connection out of the pool, the second WithTx will block until something puts it back in the pool. This trends towards infinity; as evidenced by CORE-2236.
As part of this change, I made the
pctx.TestContext
logger actually panic during DPANIC logs, and fixed the places that panicked. (It was only nested database transactions.) So nowlog.Dpanic
will always fail tests, which has been a goal of mine for a while. Panics do not happen in production; you only get a stack trace and a log message there. If a bug sneaks in, it's not a big deal.To ensure that the WithTx check is actually being used, I have adjusted the other transaction-starting helpers, transactionenv.WithReadContext and WithWriteContext to propagate WithTx's context to the callback. That way, any nesting that happens inside a WithReadContext block will trigger the panic. I found 0 cases that actually do this.
This change is part of CORE-2246.