Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/workerd/io/limit-enforcer.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ class IsolateLimitEnforcer: public kj::Refcounted {
return 128 * 1024 * 1024; // 128 MB
}

// How long a Durable Object storage operation may hold the output gate before the gate breaks
// and the object is reset. This only protects against total hangs. Lowering it much in
// production is risky, since a low timeout can fire spuriously under heavy CPU load and fail
// requests that would otherwise succeed; tests lower it to exercise the timeout quickly.
virtual kj::Duration getOutputGateTimeout() const {
Comment thread
danlapid marked this conversation as resolved.
Resolved
return 30 * kj::SECONDS;
}

// IoContext::awaitJs() calls this when the promise it waits for is never settled, which can be
// in a GC finalizer or without the isolate lock, so it must neither enter V8 nor need the lock.
virtual bool hasExcessivelyExceededHeapLimit() const = 0;
Expand Down
21 changes: 13 additions & 8 deletions src/workerd/io/worker.c++
Original file line number Diff line number Diff line change
Expand Up @@ -4199,10 +4199,14 @@ struct Worker::Actor::Impl {
public ActorCache::Hooks,
private kj::TaskSet::ErrorHandler {
public:
HooksImpl(kj::Own<Loopback> loopback, TimerChannel& timerChannel, ActorObserver& metrics)
HooksImpl(kj::Own<Loopback> loopback,
TimerChannel& timerChannel,
ActorObserver& metrics,
kj::Duration outputGateTimeout)
: loopback(kj::mv(loopback)),
timerChannel(timerChannel),
metrics(metrics) {}
metrics(metrics),
outputGateTimeout(outputGateTimeout) {}

void inputGateLocked() override {
metrics.inputGateLocked();
Expand All @@ -4219,11 +4223,8 @@ struct Worker::Actor::Impl {
// Implements InputGate::Hooks.

kj::Promise<void> makeTimeoutPromise() override {
// This really only protects against total hangs. Lowering the timeout drastically is risky,
// since low timeouts can spuriously fire when under heavy CPU load, failing requests that
// would otherwise succeed.
auto timeout = 30 * kj::SECONDS;
co_await timerChannel.afterLimitTimeout(timeout);
// See IsolateLimitEnforcer::getOutputGateTimeout() for why this is long.
co_await timerChannel.afterLimitTimeout(outputGateTimeout);

auto e = KJ_EXCEPTION(OVERLOADED,
"broken.outputGateBroken; jsg.Error: Durable Object storage operation exceeded "
Expand Down Expand Up @@ -4265,6 +4266,7 @@ struct Worker::Actor::Impl {
kj::Own<Loopback> loopback; // only for updateAlarmInMemory()
TimerChannel& timerChannel; // only for afterLimitTimeout() and updateAlarmInMemory()
ActorObserver& metrics;
kj::Duration outputGateTimeout;

kj::Maybe<kj::Promise<void>> maybeAlarmPreviewTask;

Expand Down Expand Up @@ -4367,7 +4369,10 @@ struct Worker::Actor::Impl {
container(kj::mv(container)),
containerImages(kj::mv(containerImages)),
facetManager(facetManager),
hooks(loopback->addRef(), timerChannel, *metrics),
hooks(loopback->addRef(),
timerChannel,
*metrics,
self.worker->getIsolate().getLimitEnforcer().getOutputGateTimeout()),
inputGate(hooks),
outputGate(hooks),
loopback(kj::mv(loopback)),
Expand Down
Loading