Skip to content

verifyMigratedDatabase: close opened handles when a later open fails - #2022

Open
kriszyp wants to merge 2 commits into
mainfrom
kris/2012-verify-handle-leak
Open

verifyMigratedDatabase: close opened handles when a later open fails#2022
kriszyp wants to merge 2 commits into
mainfrom
kris/2012-verify-handle-leak

Conversation

@kriszyp

@kriszyp kriszyp commented Jul 31, 2026

Copy link
Copy Markdown
Member

Small follow-up to #2014: verifyMigratedDatabase opened rootStore and dbisDb before its try, so a throw opening the second store (lock contention, corrupt CF) leaked the first — holding the RocksDB lock on exactly the diagnostic path operators use after a broken migration. Now every open is tracked in a handles array closed in finally with per-handle error guarding, the same pattern copyDbToRocks uses.

Caught by the gemini + claude review bots on the v5.1 backport (#2020, fixed there in a6eb7b9); this ports the identical fix to main. No patch label needed — #2020 already carries it for the v5.1 line.

Migration unit tests: 7 passing under LMDB engine locally.

🤖 Generated with Claude Code (Claude Fable 5)

@kriszyp
kriszyp requested a review from sleekmountaincat July 31, 2026 04:10

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates verifyMigratedDatabase in bin/copyDb.ts to track open database handles in an array, ensuring they are all closed in a finally block even if an error occurs during initialization. The reviewer noted that pushing all individual column family handles (rawDbi) to this array keeps them open concurrently for the entire verification process, which could exceed file descriptor limits. They suggested closing each rawDbi immediately after use while keeping only the main database handles in the tracking array.

Comment thread bin/copyDb.ts Outdated
Comment thread bin/copyDb.ts Outdated
@claude

claude Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Reviewed; no blockers found.

kriszyp added a commit that referenced this pull request Jul 31, 2026
…iew on #2022)

Keeps the v5.1 backport identical to main: only rootStore/dbisDb need the
leak-safety array; per-table CF handles close immediately.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kriszyp
kriszyp marked this pull request as ready for review July 31, 2026 09:17
@kriszyp
kriszyp requested review from heskew and ldt1996 and removed request for sleekmountaincat July 31, 2026 12:14
…tial-open failure

Track every open in a handles array closed in finally (the copyDbToRocks
pattern): a throw opening the second store leaked the first, holding the
RocksDB lock on the diagnostic path operators use after a broken
migration. Caught by the review bots on the v5.1 backport (#2020) of
the change that introduced it (#2014).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kriszyp
kriszyp force-pushed the kris/2012-verify-handle-leak branch from 67895b2 to e2ee8c2 Compare July 31, 2026 12:25
…iew)

Only rootStore/dbisDb need the leak-safety array (opened before the loop
can fail); per-table CF handles close immediately so a many-table sweep
does not hold them all open against fd limits.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant