Repository navigation
[fix][schema] Fix BookKeeper read handle leaks on schema read failures - #26818
Conversation
Always close an opened schema read handle after the read attempt, retaining the original read failure if cleanup also fails. Main Issue: apache#26815 Assisted-by: OpenAI Codex
Unwrap asynchronous errors before attaching suppressed close failures. Exercise delayed read and close callbacks, malformed schema entries, failed opens, and synchronous exceptions. Assisted-by: OpenAI Codex
Denovo1998
left a comment
There was a problem hiding this comment.
Nice fix! The read handle is now closed on both asynchronous and synchronous failures, and waiting for the close to complete before finishing the read looks right to me.
I also checked the exception handling. Keeping the original read/decode error as the primary failure and attaching the close error as suppressed makes sense.
I didn't spot any blocking issues in the current changes. Just need the CI checks to run successfully.
lhotari
left a comment
There was a problem hiding this comment.
LGTM. Thanks for tracking down this read handle leak and for covering each outcome with a test.
I traced the new readSchemaEntry chain at BookkeeperSchemaStorage.java:578-598. After a successful open, close is attempted exactly once on read success, read failure, decode failure and a synchronous throw from asyncReadEntries. A synchronous throw from asyncClose is also caught. The read or decode error stays primary, and the close error is attached as suppressed (self-suppression is guarded). A close failure after a successful read still fails the read, as before. The result completes once, and nothing blocks.
The test checks that the read future stays pending until the read and close callbacks fire, and that asyncClose is called once.
One optional readability thought, not blocking: the nested handle(...)/thenCompose(Function.identity()) expression could move into a small private helper such as closeAfter(ledger, readFuture). That would make the single-completion and suppression logic easier to read. I did not run the tests; CI still needs to pass.
#26818) Co-authored-by: Lari Hotari <[email protected]> (cherry picked from commit 3cd96c7)
#26818) Co-authored-by: Lari Hotari <[email protected]> (cherry picked from commit 3cd96c7)
apache#26818) Co-authored-by: Lari Hotari <[email protected]> (cherry picked from commit 3cd96c7)
apache#26818) Co-authored-by: Lari Hotari <[email protected]> (cherry picked from commit 3cd96c7)
Main Issue: #26815
Motivation
Schema storage closes an opened BookKeeper read handle only when the entry read succeeds. A failed read bypasses cleanup and can leave the handle and its metadata listener retained.
Modifications
Failed reads remain failed; this change does not introduce retries or modify BookKeeper watch registration.
Verifying this change
Local validation passed as described below. Full CI validation is still pending.
BookkeeperSchemaStorageReadHandleTestcovers nine outcomes through the public storage read path. Tests delay read/close callbacks to check ordering, use malformed serialized bytes for decoding failures, assert exactly one close after a successful open, and verify both the primary and suppressed errors. The failed-open control verifies that no read or close is attempted.With the tests unchanged and only the production changes removed (base
1046481c970067cbca9c80a25a98257b9179a3da), four cases fail: three read-failure paths never invoke close, and a combined decode/close failure loses the decode error. The other five are compatibility controls that pass on both versions.The two combined-failure cases also fail against the initial PR implementation: the close error was attached to an asynchronous wrapper and was lost when the caller unwrapped the original error. The updated implementation preserves it on the underlying cause.
With the fix restored, all nine cases and 19 related existing tests pass (28 total), along with
quickCheck:Does this pull request potentially affect one of the following parts: