Skip to content

Commit

Permalink
fixup! Evict actors after 10 sec inactivity in Workerd
Browse files Browse the repository at this point in the history
  • Loading branch information
MellowYarker committed Oct 11, 2023
1 parent 0c79dcd commit 53df814
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/workerd/server/server.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1415,8 +1415,11 @@ public:
ref.container = kj::none;
}

// Don't erase the onBrokenTask if it is the reason we are being destroyed.
if (!onBrokenTriggered) {
parent.onBrokenTasks.erase(key);
}
// We need to make sure we're removed from the actors map.
parent.onBrokenTasks.erase(key);
parent.actors.erase(key);
}

Expand Down Expand Up @@ -1506,6 +1509,9 @@ public:
bool hasClients() { return containerRef != kj::none; }
kj::Maybe<ActorContainerRef&> getContainerRef() { return containerRef; }

// `onBrokenTriggered` indicates the actor has been broken.
void setOnBroken() { onBrokenTriggered = true; }

// The actor is constructed after the ActorContainer so it starts off empty.
kj::Maybe<kj::Own<Worker::Actor>> actor;
private:
Expand All @@ -1516,6 +1522,7 @@ public:
kj::TimePoint lastAccess;
kj::Maybe<kj::Own<Worker::Actor::HibernationManager>> manager;
kj::Maybe<kj::Promise<void>> shutdownTask;
bool onBrokenTriggered = false;

// Non-empty if at least one client has a reference to this actor.
// If no clients are connected, we may be evicted by `cleanupLoop`.
Expand Down Expand Up @@ -1779,7 +1786,10 @@ public:
}
// Note that we remove the entire ActorContainer from the map -- this drops the
// HibernationManager so any connected hibernatable websockets will be disconnected.
actors.erase(entryRef.getKey());
entryRef.setOnBroken();
auto key = kj::str(entryRef.getKey());
actors.erase(key.asPtr());
onBrokenTasks.erase(key);
}
};

Expand Down

0 comments on commit 53df814

Please sign in to comment.