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 bazelbuild#22051
  • Loading branch information
werkt committed Apr 25, 2024
1 parent c5cb07a commit 08f0e0e
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.
*
* 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 08f0e0e

Please sign in to comment.