You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: release database cache runners after failed removals - #12938
DbQueryResultCache.remove() skips releasing its owned query runner when a deletion rejects. If a deletion fails, first settle any other deletions already using the same runner, attempt cleanup, then rethrow the original error. A cleanup failure cannot replace that deletion error; if all deletions succeeded, a cleanup failure is still surfaced. Caller-supplied runners are never released.
Successful removal keeps the same per-identifier SQL and parallel scheduling. There are no additional queries, batching/parameter-limit changes, or new dependencies. The extra settlement pass only runs after a failure. Waiting for already-started deletions avoids returning a still-busy connection to the pool.
This closes the remaining removal error path after #8969's successful-removal cleanup. #12797/#12545 protect other database-cache methods.
Validation (Node.js 22.17.1, PostgreSQL 15.6):
On unchanged master, new tests fail for the unreleased runner and early settlement while a second deletion is pending.
Removal tests cover empty/single/multiple identifiers, both runner owners, deferred deletion cleanup, and synchronous/asynchronous cleanup errors after successful or failed deletions.
Real PostgreSQL failure/reuse tests and the existing query-builder cache suite pass. The test's single-connection settings override local pool defaults without discarding other connection options.
Full unit and functional-cache run: 164 passing, 4 pending. After the final test-fixture corrections, the source removal-unit/functional-cache run has 25 passing, 4 pending; the custom-schema removal run has 15 passing. The custom-schema cases fail before qualifying the dropped table. An intentionally failing second connection also exits without forced Mocha shutdown, verifying earlier initialized connections are closed by teardown.
Complete TypeScript compilation, focused ESLint (no errors), formatting and diff checks pass. Other database servers were not run locally; CI supplies the broader driver matrix.
Developed with AI assistance; source, prior fixes, regression behavior, and final diff reviewed.
Pull-Request Checklist
Code is up-to-date with the master branch
This pull request links a relevant issue using a closing keyword
There are new or updated tests validating the change
Documentation has been updated to reflect this change — N/A: restores resource cleanup without a new API/configuration
1. Cache tests fail with a custom schema✓ Resolved
Description
The test drops "query-result-cache" without qualifying it with the configured schema, although
DbQueryResultCache creates its table using that schema. When a PostgreSQL test connection
specifies a schema outside the search path, the drop fails before either removal assertion runs.
The test retains connection configuration, including schema; the cache constructs its table name
from that schema, but the new DROP statement names only the unqualified table.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The regression test drops an unqualified cache table, so PostgreSQL connections configured with a non-default schema can fail before testing removal.
## Fix Focus Areas
- packages/typeorm/test/functional/cache/db-cache-remove.test.ts[45-45]
## Recommended Fix
Build and escape the cache table name using the test connection's configured schema before dropping it.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. A failed test setup can leave pools open✓ Resolved
Description
The before hook assigns dataSources only after every concurrent initialization succeeds, while
the after hook can close only the assigned array. If one of multiple configured PostgreSQL
connections fails to initialize after another succeeds, the successful connection remains open and
the test process can stay alive.
The setup helper can return multiple PostgreSQL configurations. Promise.all rejects without
assigning its result when any initialization fails, and the cleanup helper does nothing when passed
an unassigned array.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
Concurrent test initialization can leave successful connections open when another initialization fails before `dataSources` is assigned.
## Fix Focus Areas
- packages/typeorm/test/functional/cache/db-cache-remove.test.ts[14-32]
- packages/typeorm/test/functional/cache/db-cache-remove.test.ts[39-39]
## Recommended Fix
Track created data sources before awaiting initialization. On setup failure, destroy any that initialized successfully, then rethrow the setup error.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
3. Callers lose the original deletion error✓ Resolved
Description
remove() rethrows a deletion error after settling pending queries, but an error from the awaited
release() in finally replaces it. When both deletion and runner cleanup fail, callers receive
the cleanup error instead of the database error that caused removal to fail.
+ } finally {+ if (!queryRunner) {+ await _queryRunner.release()
Evidence
The new catch rethrows the deletion failure, while the new finally awaits release afterward; a
rejection from that await supersedes the pending throw. PostgreSQL release invokes a pool callback,
so cleanup is an operation that can itself fail.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
A failing runner release can override the original deletion error rethrown by `remove()`.
## Fix Focus Areas
- packages/typeorm/src/cache/DbQueryResultCache.ts[355-363]
- packages/typeorm/test/unit/cache/db-query-result-cache.test.ts[36-53]
## Recommended Fix
Preserve the deletion error if release also fails, while still surfacing a release failure when deletion succeeded. Add a test in which both operations reject.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
View review recommended (1) 4. Cache tests can run with the wrong pool✓ Resolved
Description
The functional test supplies poolSize and extra through driverSpecific, but
setupTestingConnections() lets corresponding values from the local configuration overwrite them.
If that configuration defines either value, the test no longer runs with its intended
single-connection pool or one-second connection timeout, making its reuse check
environment-dependent.
The test requests its pool settings through driverSpecific, but the helper merges that object
before the configuration-derived options. The PostgreSQL driver then uses the resulting poolSize
and extra values to construct its pool.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
Local PostgreSQL configuration can override the pool settings required by the removal regression test.
## Fix Focus Areas
- packages/typeorm/test/functional/cache/db-cache-remove.test.ts[13-21]
- packages/typeorm/test/utils/test-utils.ts[254-264]
## Recommended Fix
Ensure the test-specific pool size and timeout take precedence over local configuration, without discarding other PostgreSQL connection settings.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Author self-review: I have reviewed the code review findings, and addressed the relevant ones.
Tip of the day
💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding
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
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
Fixes #12935.
DbQueryResultCache.remove()skips releasing its owned query runner when a deletion rejects. If a deletion fails, first settle any other deletions already using the same runner, attempt cleanup, then rethrow the original error. A cleanup failure cannot replace that deletion error; if all deletions succeeded, a cleanup failure is still surfaced. Caller-supplied runners are never released.Successful removal keeps the same per-identifier SQL and parallel scheduling. There are no additional queries, batching/parameter-limit changes, or new dependencies. The extra settlement pass only runs after a failure. Waiting for already-started deletions avoids returning a still-busy connection to the pool.
This closes the remaining removal error path after #8969's successful-removal cleanup. #12797/#12545 protect other database-cache methods.
Validation (Node.js 22.17.1, PostgreSQL 15.6):
Developed with AI assistance; source, prior fixes, regression behavior, and final diff reviewed.
Pull-Request Checklist
masterbranch