[BUG]: properly catch and propogate panics in component handlers #3374
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.
Description of changes
In Rust, panics (should) always semantically indicate a program bug. By default panics will terminate the current thread. This makes sense for single-tenant programs, e.g. CLI tools, GUI programs, etc.
However, if we assume that most program bugs are triggered via user-provided input, this behavior is much less desirable for multi-tenant systems. A bad code path triggered by a small percentage of users should not cause service degradation for all users.
Given this, I decided to continue down the path of catching panics rather than crashing the entire process upon a panic.
This approach (I assume because of similar reasoning) is also taken by tonic, our gRPC server, which catches panics at the gRPC service handler layer. Tokio also catches panics at the task level.
This PR cleans up panic-related code and adds logic to catch panics inside component handlers (this is where we have previously observed hangs because of improperly handled panics).
Test plan
How are these changes tested?
pytest
for python,yarn test
for js,cargo test
for rustAlso tested by inserting a panic! into a compaction handler and observing that the error correctly propagated and compaction continued to progress (previously hung the process).
Documentation Changes
Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?
n/a