Skip to content

[#819] Release the log when a changelog DB constructor cannot read its limits - #833

Open
vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:issues/819-filereplicadb-log-leak
Open

[#819] Release the log when a changelog DB constructor cannot read its limits#833
vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:issues/819-filereplicadb-log-leak

Conversation

@vharseko

@vharseko vharseko commented Aug 3, 2026

Copy link
Copy Markdown
Member

Fixes #819.

FileReplicaDB opened its log first and read the CSN limits afterwards: when that read failed (an unreadable changelog file, the #802 scenario), the constructor threw with the Log instance already reference-counted in the JVM-wide Log.logsCache and nobody left to close it — the instance holding the reference was never returned. The cache entry stayed pinned for the lifetime of the JVM together with its file handles, and the next open of the same path got the stale instance back: in the test suite that means a Log whose files a removeDB() may have deleted in the meantime (the class of cascades behind #813).

FileChangeNumberIndexDB had the same shape around its change number initialization, so it gets the same guard.

Both constructors now close the log before rethrowing, as shutdown() does with the same log. RuntimeException is covered too, following the LogFile constructor's own cleanup pattern.

The new FileReplicaDBTest#testFailedConstructorReleasesLog reproduces the leak: it plants a rotated log file with an undecodable record (rotated files are opened without validation — their bounds come from the file name — so reading the oldest CSN is the first operation touching the content), asserts the constructor fails, removes the corrupted file and asserts reopening succeeds. Without the fix the reopen receives the stale cached Log still holding the deleted file and fails with Could not open a reader on log file ….

…uctor cannot read its limits

FileReplicaDB opened its log and read the CSN limits afterwards: when that
read failed, the constructor threw with the Log instance already reference
counted in the JVM-wide log cache and nobody left to close it. The entry
stayed pinned together with its file handles, and the next open of the same
path got the stale instance back. FileChangeNumberIndexDB had the same shape
around its change number initialization.

Close the log before rethrowing, as shutdown() does with the same log.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileReplicaDB leaks its log reference when its constructor cannot read the CSN limits

2 participants