Repository navigation
fix(cache): release query runners created by clear and getFromCache - #12797
Merged
alumni merged 3 commits intoAug 26, 2026
Merged
Conversation
DbQueryResultCache.clear and getFromCache create a query runner through getQueryRunner when the caller passes none, but never release it. Calling dataSource.queryResultCache.clear repeatedly leaks a pooled connection each time (its interface argument is optional, and CacheClearCommand invokes it with no argument), and after poolSize calls every later query waits forever. Release the self-created runner in a finally block, matching the existing remove and storeInCache methods, and keep the original return value.
commit: |
Code Review by Qodo
1.
|
Type the createQueryRunner stub with ReplicationMode and undo it with Reflect.deleteProperty rather than casting through any, and run Prettier over the file.
Spanner rejects the built-in cache table name, so DataSource.synchronize fails in beforeEach when the cache is enabled. The other cache suites already exclude spanner through disabledDrivers; do the same here.
alumni
approved these changes
Aug 26, 2026
This was referenced Oct 5, 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 of change
DbQueryResultCache.clear and getFromCache build a query runner through getQueryRunner when the caller passes none, and never release it. The interface types the argument as optional and CacheClearCommand calls clear with no argument, so calling dataSource.queryResultCache.clear from application code (an admin endpoint, a scheduled job, a test teardown) leaks one pooled connection per call. After poolSize calls the pool is exhausted and every later query waits forever.
The fix releases the self-created runner in a finally block, the same way remove and storeInCache already do, and keeps the original return value. A runner passed in by the caller is left untouched. getFromCache has the same shape and is covered by the same change.
Verified with poolSize 2 on Postgres 16: without the fix the third argument-less clear times out once the pool is drained; with the fix the three clears complete and a following query still runs. Added a test that spies on createQueryRunner and asserts the self-created runner is released by clear and getFromCache, that a runner passed in by the caller is not released, and that the self-created runner is still released when the underlying operation throws.
Pull-Request Checklist
masterbranchtest/functional/cache/query-runner-release.test.ts)