Skip to content

Commit

Permalink
Avoids timeout computation overflow
Browse files Browse the repository at this point in the history
Summary:
This change prevents a deadlock from occurring when
condition_variable::wait_until can't handle really
large timeouts by using wait() instead of wait_until()
when no deadlines are being watched for.

Reviewed By: neildhar

Differential Revision: D39361645

fbshipit-source-id: 130b9c3ecc557eac08ba090276a9b977bbdbb707
  • Loading branch information
jpporto authored and facebook-github-bot committed Sep 9, 2022
1 parent 158ab06 commit ae5dc7f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/VM/TimeLimitMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,18 @@ void TimeLimitMonitor::timerLoop() {
}
}

// Sleep until the next deadline is reached, or the a notification comes in
// (e.g., time limit monitoring has been disabled and the thread needs to
// terminate). Note that spurious wake ups are OK -- it just means that no
// timeouts will have passed, and the thread will go back to waiting.
timerLoopCond_.wait_until(lockGuard, nextDeadline);
if (nextDeadline != NoDeadline) {
// Sleep until the next deadline is reached, or the notification comes in
// (e.g., time limit monitoring has been disabled and the thread needs to
// terminate). Note that spurious wake ups are OK -- it just means that no
// timeouts will have passed, and the thread will go back to waiting.
timerLoopCond_.wait_until(lockGuard, nextDeadline);
} else {
// Work around overflow issues in some libstdcxx implementations by using
// wait() when there's no active deadline. The timerLoop will be notified
// by the VM thread when a new Runtime is registered or destroyed.
timerLoopCond_.wait(lockGuard);
}
}
}

Expand Down

0 comments on commit ae5dc7f

Please sign in to comment.