Skip to content

[WIP] fix: close ViewStore on IModelDb.close and disconnect V2 checkpoint containers on shutdown#9539

Draft
anmolshres98 wants to merge 1 commit into
masterfrom
anmolshres98/issue-5017-flaky-handle-leak
Draft

[WIP] fix: close ViewStore on IModelDb.close and disconnect V2 checkpoint containers on shutdown#9539
anmolshres98 wants to merge 1 commit into
masterfrom
anmolshres98/issue-5017-flaky-handle-leak

Conversation

@anmolshres98

@anmolshres98 anmolshres98 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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 by accessViewStore(), leaving its CloudContainer connected with an hourly token-refresh timer
  • V2 checkpoint containers were only disconnected by the test-only V2CheckpointManager.cleanup(), never on host shutdown

-- created w/ help from AnmolDroid🤖

…ontainers on shutdown so cloud containers no longer leak (#5017)
Copilot AI review requested due to automatic review settings July 23, 2026 21:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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() via V2CheckpointManager.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";
@anmolshres98

Copy link
Copy Markdown
Contributor Author

/azp run iTwin.js, iTwin.js Integration - GitHub, iTwin.js Docs - YAML

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@iTwin iTwin deleted a comment from azure-pipelines Bot Jul 23, 2026
@iTwin iTwin deleted a comment from azure-pipelines Bot Jul 23, 2026
@anmolshres98 anmolshres98 changed the title [WIP] fix: close ViewStore on IModelDb.close and disconnect V2 checkpoint containers on shutdown so cloud containers no longer leak (#5017) [WIP] fix: close ViewStore on IModelDb.close and disconnect V2 checkpoint containers on shutdown Jul 24, 2026
@anmolshres98 anmolshres98 linked an issue Jul 24, 2026 that may be closed by this pull request
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.

Flaky test - Handle leak detected

2 participants