fix: implement framework-wide thread interruption handling (#895) - #895
Open
symphony-enrico wants to merge 6 commits into
Open
fix: implement framework-wide thread interruption handling (#895)#895symphony-enrico wants to merge 6 commits into
symphony-enrico wants to merge 6 commits into
Conversation
This commit addresses the issue of thread interruptions mistakenly being retried and logged as transient network errors within blocking HTTP clients, authentication loops, event pull loops, and paginated query services. Specifically: - Implemented static helper `checkInterruptionAndThrow` in `RetryWithRecovery` to centralize detection of thread interruption/cancellation, restore the physical thread's interrupted flag, and cleanly throw/propagate a standard `CancellationException` without nested wrapping. - Simplified all service-level try-catch retry loops to reuse this centralized Helper, eliminating redundant exception-mapping boilerplate. - Added localized traversal check in Jersey `ApiClientJersey2` to silent abort and cleanly propagate `CancellationException` during connection interrupts. - Enhanced `AbstractDatafeedLoop` to exit cleanly and silently upon task interruption to secure thread-pool teardown. - Added comprehensive unit tests covering all services, authentication loops, and client layers, achieving 100% test coverage with zero regressions. - Updated OpenAPI change documentation and specifications under openspecs.
- Archived the completed change `interrupted-retry-fix` to `openspec/changes/archive/2026-08-25-interrupted-retry-fix/`. - Synced and created the new main specification at `openspec/specs/request-interruption/spec.md`.
This commit addresses the issue where Resilience4jRetryWithRecovery would still schedule redundant retries and log verbose "Retry in 0.5s..." messages when a thread was cancelled or interrupted during operations like bootstrapping agentless client keys. Specifically: - Wrapped BDK's Resilience4j retry predicate with a safe fail-fast decorator (`!isInterruption(throwable) && retryOnExceptionPredicate.test(throwable)`). - This ensures that if any interruption or CancellationException is detected in the exception's cause chain, Resilience4j immediately aborts and propagates the cancellation without scheduled retries. - Added a dedicated unit test to `Resilience4jRetryWithRecoveryTest` confirming interrupted/cancelled operations bypass retries even when the underlying exception otherwise matches the retry predicate.
…sign choice - Documented the new Resilience4j fail-fast retry predicate wrapper design choice (D5) in `design.md`. - Documented `Resilience4jRetryWithRecovery.java` impact in `proposal.md`.
…ning - Distinguish between logical task cancellation (CancellationException) and physical thread interruption (InterruptedException). - Restore the physical thread interrupted status only if the cause chain contains an actual InterruptedException, avoiding thread-pool poisoning from logical cancellations. - Updated RetryWithRecovery, AbstractDatafeedLoop, and ApiClientJersey2 logic, alongside the request-interruption specifications.
…tively aborting - In RetryWithRecovery and ApiClientJersey2, throw a CancellationException wrapping a newly created InterruptedException if the thread is found to be already interrupted prior to execution. - This ensures physical thread interruptions are fully traceable and detectable in the exception cause chain downstream, preventing confusion with logical task cancellations.
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.
This commit addresses the issue of thread interruptions mistakenly being retried and logged as transient network errors within blocking HTTP clients, authentication loops, event pull loops, and paginated query services.
Specifically:
checkInterruptionAndThrowinRetryWithRecoveryto centralize detection of thread interruption/cancellation, restore the physical thread's interrupted flag, and cleanly throw/propagate a standardCancellationExceptionwithout nested wrapping.ApiClientJersey2to silent abort and cleanly propagateCancellationExceptionduring connection interrupts.AbstractDatafeedLoopto exit cleanly and silently upon task interruption to secure thread-pool teardown.