fix: ignore redundant interrupted exceptions#1777
Conversation
There was a problem hiding this comment.
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.
|
/gemini review. |
There was a problem hiding this comment.
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.
8574e1b to
2f38d7e
Compare
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
2f38d7e to
0ce7fe3
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
The
awaitTerminationonretrySchedulerwas added in #1734 as boilerplate when we removed someThread.sleeps. TheawaitTerminationcalls in the shutdown chain throwInterruptedExceptionwhen the SDK's shutdown timeout fires and sets the interrupt flag. This is harmless but noisy.This PR adds a
ShutdownUtils.awaitTerminationQuietly()utility that catchesInterruptedExceptionand restores the interrupt flag. It's applied to all threeawaitTerminationsites in the shutdown chain. This is safe because nothing further up the call stack relies onInterruptedExceptionfrom 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)toSyncStreamQueueSource.shutdown()to preventgrpcComponentsfrom being swapped byreinitializeChannelComponents()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.