Repository navigation
fix(date): release the transaction before acquiring more pool connections - #134
Merged
Merged
Conversation
…ions The date handler held its transaction for the whole request, including the git2 blob read, and meanwhile get_doc_version_dates acquired further connections from the pool. With 2 * num_cpus concurrent requests each holding its first connection, all of them waited on a second one until sqlx's 30s acquire timeout, stalling every other handler on the pool. Run the handler's three transactional reads (publication, commit, latest publication) up front, then commit the read-only transaction so no request ever holds more than one connection at a time and none is held across the git read. Fixes #133
BojanG99
approved these changes
Oct 8, 2026
This file contains hidden or 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
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.
Description (e.g. "Related to ...", etc.)
Closes #133.
The
_datehandler kept a database connection open for the whole request, then asked the pool for a second one partway through. When enough requests did this at once, each one held a connection while waiting for another, so all of them waited until the 30s timeout and the rest of the server stalled with them.What was done differently from the issue
The issue suggests keeping the transaction open and passing it down into
get_doc_version_dates. This PR does something simpler:So each request uses one connection at a time and never holds one while waiting for another. That removes the deadlock just like the suggested fix would. It also stops holding a connection during the git read, which the issue said makes the problem worse.
It's also a much smaller change. The suggested fix would mean rewriting four database lookup functions and code that
versions()also uses. This one only touches the date handler (8 lines added, 2 removed).The trade-off is that the version-date lookups no longer run inside the same transaction. That doesn't matter here because the handler only reads data.
Audit
As the issue suggested, I looked for the same pattern elsewhere. The only other transaction is the command-line import in
src/history/changes.rs, which never takes a second connection from the pool.serve()andversions()don't open transactions.Checked
cargo fmt --checkandcargo clippy --all-targetspass, and all 72 unit tests pass..taffolders on the local drives. CI will run them./_daterequests.Code review checklist (for code reviewer to complete)
Automated tests, benchmarks and linters
You can run the tests, lints and benchmarks that are run on CI locally with: