RANGER-5476: PolicyRefresher.stopRefresher() can deadlock when retrying HTTP request #832
+207
−0
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 PolicyRefresher.stopRefresher() method can deadlock because it interrupts the refresher thread and then waits for it to complete using join(). However, if the RangerRESTClient is currently in its retry loop due to server errors (such as 503 Service Unavailable), it catches the InterruptedException during its Thread.sleep() interval but fails to propagate the interruption signal or break the retry logic. By swallowing this exception, the client clears the thread's interrupted status and continues the for loop, preventing the thread from ever terminating. This leaves the calling thread blocked indefinitely on join().
What changes were proposed in this pull request?
The fix involves updating the shouldRetry() method in RangerRESTClient to properly handle the InterruptedException by restoring the thread's interrupted status via Thread.currentThread().interrupt() and returning false. This ensures that the retry loop is aborted immediately when a shutdown is requested, allowing the thread to exit gracefully and unblocking the stopRefresher() call without negatively impacting normal failover logic.
How was this patch tested?
New test added which fails without fix and passes after fix.