Skip to content

Commit

Permalink
Prevent currentThread().join() on cli thread crash
Browse files Browse the repository at this point in the history
If the cli-update-thread is crashing, it may attempt to interrupt and join on itself. Hopefully no updateThread could be in stopUpdateThread without going through handleCrash() -> Event.FATAL sequence through BlazeRuntime.

Fixes #22051

Closes #22122.

PiperOrigin-RevId: 633653817
Change-Id: Iaef5df56358d74bd7210ad8cb3562b452de9eb6a
  • Loading branch information
werkt authored and Copybara-Service committed May 14, 2024
1 parent 7025bb8 commit 6306240
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -981,11 +981,15 @@ private void startUpdateThread() {
* Stop the update thread and wait for it to terminate. As the update thread, which is a separate
* thread, might have to call a synchronized method between being interrupted and terminating, DO
* NOT CALL from a SYNCHRONIZED block, as this will give the opportunity for dead locks.
*
* <p>If this is called from the updateThread itself, ignore the interrupt/join, as it is
* hopefully handling a FATAL, and should be terminating anyway.
*/
private void stopUpdateThread() {
shutdown = true;
Thread threadToWaitFor = updateThread.getAndSet(null);
if (threadToWaitFor != null) {
// we could be second to wait here, or be the current thread, which would hang
if (threadToWaitFor != null && threadToWaitFor != Thread.currentThread()) {
threadToWaitFor.interrupt();
Uninterruptibles.joinUninterruptibly(threadToWaitFor);
}
Expand Down

0 comments on commit 6306240

Please sign in to comment.