Skip to content

Commit

Permalink
DeadlineManager: do exponential backoff on notification failures
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 713632233
Change-Id: I3718413983cce62027d17ee71dcf350417c5659b
  • Loading branch information
happyCoder92 authored and copybara-github committed Jan 9, 2025
1 parent 9add401 commit 899792a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sandboxed_api/sandbox2/util/deadline_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <sys/syscall.h>

#include <algorithm>
#include <csignal>
#include <memory>

Expand All @@ -37,7 +38,7 @@ ABSL_FLAG(int, sandbox2_deadline_manager_signal, SIGRTMAX - 1,

namespace sandbox2 {
namespace {
constexpr int kFailedNotificationsThreshold = 100;
constexpr int kFailedNotificationsThreshold = 32;

absl::Time RoundUpTo(absl::Time time, absl::Duration resolution) {
return time == absl::InfiniteFuture()
Expand Down Expand Up @@ -160,8 +161,6 @@ void DeadlineManager::Run() {
next_deadline)) {
continue;
}
absl::Time next_notification_time =
RoundUpTo(absl::Now() + kResolution, kResolution);
while (!queue_.empty() && (*queue_.begin())->deadline <= next_deadline) {
DeadlineRegistration::Data* entry = *queue_.begin();
queue_.erase(queue_.begin());
Expand All @@ -170,6 +169,13 @@ void DeadlineManager::Run() {
VerifySignalHandler();
}
if (entry->in_blocking_fn) {
constexpr int kExponentialBackoffRate = 8;
constexpr int kMaxExponentialBackoff = 10;
int exp_backoff =
1 << std::min(entry->notification_attempt / kExponentialBackoffRate,
kMaxExponentialBackoff);
absl::Time next_notification_time =
RoundUpTo(absl::Now() + kResolution * exp_backoff, kResolution);
util::Syscall(__NR_tgkill, getpid(), entry->tid, signal_nr_);
entry->deadline = next_notification_time;
queue_.insert(entry);
Expand Down

0 comments on commit 899792a

Please sign in to comment.