[WIP] fix: close ViewStore on IModelDb.close and disconnect V2 checkpoint containers on shutdown#9539
Draft
anmolshres98 wants to merge 1 commit into
Draft
[WIP] fix: close ViewStore on IModelDb.close and disconnect V2 checkpoint containers on shutdown#9539anmolshres98 wants to merge 1 commit into
anmolshres98 wants to merge 1 commit into
Conversation
…ontainers on shutdown so cloud containers no longer leak (#5017)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses residual cloud container handle leaks by ensuring CloudSqlite-backed resources are deterministically disconnected during iModel close and host shutdown, and by making container leaks visible again by allowing connected containers to keep the Node process alive.
Changes:
- Close an iModel’s ViewStore during
IModelDb.close()and clarify ViewStore ownership semantics. - Disconnect V2 checkpoint containers during
IModelHost.shutdown()viaV2CheckpointManager.cleanup(). - Revert CloudSqlite token-refresh timer
.unref()behavior so connected containers keep the process alive; tighten mocha-reporter leak detection timeout; add test hygiene + docs/change notes.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tools/build/src/mocha-reporter/index.ts | Reduce default handle-leak detection timeout and simplify call site. |
| full-stack-tests/backend/src/integration/CloudWorkspace.test.ts | Ensure OwnedWorkspace is closed to prevent leaked containers during tests. |
| docs/changehistory/NextVersion.md | Document cloud container lifecycle behavior changes and leak-failure behavior. |
| core/backend/src/IModelHost.ts | Invoke V2 checkpoint cleanup during shutdown (note: currently adds a static import). |
| core/backend/src/IModelDb.ts | Close ViewStore when iModel closes; document that the iModel owns its ViewStore. |
| core/backend/src/CloudSqlite.ts | Remove .unref() from token-refresh timer to keep process alive when containers leak. |
| core/backend/src/CheckpointManager.ts | Update cleanup documentation to reflect shutdown usage. |
| common/changes/@itwin/core-backend/*.json | Rush change note for backend lifecycle/leak behavior. |
| common/changes/@itwin/build-tools/*.json | Rush change note for mocha-reporter timeout reduction. |
| common/api/core-backend.api.md | API report update for new internal close hook + doc tag adjustments. |
Comments suppressed due to low confidence (1)
core/backend/src/IModelHost.ts:722
- Calling V2CheckpointManager.cleanup() via a static import makes IModelHost depend on CheckpointManager at module load time, creating a circular dependency (CheckpointManager imports IModelHost). Consider dynamically importing CheckpointManager here to avoid circular-load edge cases during startup/shutdown.
// safe to disconnect checkpoint containers here: open iModels were already closed by IModelDb's onBeforeShutdown listener above
V2CheckpointManager.cleanup();
CloudSqlite.CloudCaches.destroy();
| import { FunctionalSchema } from "./domains/FunctionalSchema"; | ||
| import { GenericSchema } from "./domains/GenericSchema"; | ||
| import { EditTxn } from "./EditTxn"; | ||
| import { V2CheckpointManager } from "./CheckpointManager"; |
Contributor
Author
|
/azp run iTwin.js, iTwin.js Integration - GitHub, iTwin.js Docs - YAML |
|
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
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.
Addresses #5017 (the residual handle leaks Travis described in the May 2025 comments, not the original certa bug fixed by #8020).
Leakage
IModelDb.close()never closed the ViewStore created byaccessViewStore(), leaving its CloudContainer connected with an hourly token-refresh timerV2CheckpointManager.cleanup(), never on host shutdown-- created w/ help from AnmolDroid🤖