Skip to content

fix: ignore redundant interrupted exceptions#1777

Merged
toddbaert merged 1 commit intomainfrom
fix/remove-unneeded-await
Apr 21, 2026
Merged

fix: ignore redundant interrupted exceptions#1777
toddbaert merged 1 commit intomainfrom
fix/remove-unneeded-await

Conversation

@toddbaert
Copy link
Copy Markdown
Member

@toddbaert toddbaert commented Apr 20, 2026

The awaitTermination on retryScheduler was added in #1734 as boilerplate when we removed some Thread.sleeps. The awaitTermination calls in the shutdown chain throw InterruptedException when the SDK's shutdown timeout fires and sets the interrupt flag. This is harmless but noisy.

This PR adds a ShutdownUtils.awaitTerminationQuietly() utility that catches InterruptedException and restores the interrupt flag. It's applied to all three awaitTermination sites in the shutdown chain. This is safe because nothing further up the call stack relies on InterruptedException from shutdown; the interrupt flag is preserved so any subsequent interruptible operations still behave. I added some basic tests for this util.

Also adds synchronized(this) to SyncStreamQueueSource.shutdown() to prevent grpcComponents from being swapped by reinitializeChannelComponents() mid-shutdown as Gemini pointed out, there's a possible race here.

I manually tested this with a very contrived test to confirm my understanding, but I don't think adding the test will add much value long term and it's weird to test for the absence of a line-of-code IMO.

@toddbaert toddbaert requested a review from a team as a code owner April 20, 2026 13:35
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the shutdown method in SyncStreamQueueSource.java by removing the call to awaitTermination for the retryScheduler. The scheduler is now immediately followed by the gRPC channel connector shutdown after shutdownNow is invoked. I have no feedback to provide as there were no review comments to evaluate.

@toddbaert
Copy link
Copy Markdown
Member Author

/gemini review.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the termination wait for the retry scheduler during the shutdown process of SyncStreamQueueSource. A review comment identifies a potential race condition between the shutdown and reinitialization methods, suggesting that the shutdown logic should be synchronized to prevent leaking gRPC channels.

@toddbaert toddbaert force-pushed the fix/remove-unneeded-await branch from 8574e1b to 2f38d7e Compare April 20, 2026 15:42
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
@toddbaert toddbaert force-pushed the fix/remove-unneeded-await branch from 2f38d7e to 0ce7fe3 Compare April 20, 2026 15:42
@toddbaert
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a ShutdownUtils utility to standardize the handling of InterruptedException during component shutdown across the flagd provider. By utilizing awaitTerminationQuietly, the implementation now suppresses the exception while correctly restoring the thread's interrupt flag. As a result, the shutdown() method signatures in several classes and interfaces, such as FlagdProvider, ChannelConnector, and Storage, have been updated to remove the throws InterruptedException declaration. Additionally, synchronization was added to the shutdown logic in SyncStreamQueueSource to improve thread safety. I have no feedback to provide as the changes are consistent and follow best practices for handling thread interruptions.

@toddbaert toddbaert changed the title fix: remove unnecessary await fix: ignore redundant interrupted exceptions Apr 20, 2026
@toddbaert toddbaert merged commit c51861e into main Apr 21, 2026
6 checks passed
@toddbaert toddbaert deleted the fix/remove-unneeded-await branch April 21, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants