fix: Improved error handling in SeekableStreamIndexTaskRunner.#19218
Merged
Conversation
The main improvement is that "persist" is moved out of a finally block, and now only happens on the normal path. This has two benefits. First, there is no point in persisting on the error path, and the in-memory index might be in a bad state anyway at that point. Second, moving the persist call out of "finally" fixes an issue where an exception thrown from "persist" would cause an exception thrown from "add" to be lost. This can come up in production when the in-memory index grows too large, causing the main code to throw an OutOfMemoryError, and then something goes wrong with the persist too. In this situation the original OutOfMemoryError would not have been logged. A secondary improvement is that we catch Throwable rather than Exception to trigger cleanup and when handling errors that occur during cleanup. This ensures we don't miss cleanup tasks when an Error is thrown by the main code, and that we don't lose the original exception if an Error is thrown by the cleanup code.
clintropolis
approved these changes
Mar 27, 2026
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.
The main improvement is that
persistis moved out of a finally block, and now only happens on the normal path. This has two benefits. First, there is no point in persisting on the error path, and the in-memory index might be in a bad state anyway at that point. Second, moving the persist call out offinallyfixes an issue where an exception thrown frompersistwould cause an exception thrown fromaddto be lost.This can come up in production when the in-memory index grows too large, causing the main code to throw an OutOfMemoryError, and then something goes wrong with the persist too. In this situation the original OutOfMemoryError would not have been logged.
A secondary improvement is that we catch Throwable rather than Exception to trigger cleanup and when handling errors that occur during cleanup. This ensures we don't miss cleanup tasks when an Error is thrown by the main code, and that we don't lose the original exception if an Error is thrown by the cleanup code.