Skip to content
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 5 commits into from Apr 11, 2024
Merged

Find and fix more nested transactions #9942

merged 5 commits into from Apr 11, 2024

Conversation

jrockway
Copy link
Member

@jrockway jrockway commented Apr 10, 2024

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 now log.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.

@jrockway jrockway marked this pull request as ready for review April 11, 2024 18:55
@jrockway jrockway requested review from a team as code owners April 11, 2024 18:55
@jrockway jrockway removed the request for review from acohen4 April 11, 2024 18:55
Copy link

codecov bot commented Apr 11, 2024

Codecov Report

Attention: Patch coverage is 95.09804% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 58.04%. Comparing base (ce31a07) to head (33e0013).

Files Patch % Lines
src/server/pfs/server/api_server.go 87.87% 4 Missing ⚠️
src/server/pfs/server/driver.go 94.44% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@brendoncarroll brendoncarroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jrockway jrockway merged commit 15b1f0f into master Apr 11, 2024
21 checks passed
@jrockway jrockway deleted the jonathan/audit-txn branch April 11, 2024 21:04
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants