Skip to content

Commit

Permalink
Merge pull request #2011 from cloudflare/milan/hibernation-segfault
Browse files Browse the repository at this point in the history
Reuse ActorContainerRef if it exists
  • Loading branch information
MellowYarker authored Apr 12, 2024
2 parents b52ddb0 + 0ff277e commit fb6ad2f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/workerd/server/server.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,18 @@ public:
entry.value = onActorBroken(actorRef->onBroken(), *actorContainer)
.eagerlyEvaluate([](kj::Exception&& e) { KJ_LOG(ERROR, e); });

KJ_IF_SOME(ref, actorContainer->getContainerRef()) {
// Although we didn't have a Worker::Actor, this ActorContainer _previously_ had one,
// and there's still at least one client with an open connection. We should continue
// to use our existing ActorContainerRef, otherwise we will have two or more separate
// refcounted ActorContainerRef's tracking the same ActorContainer. This would likely
// result in memory corruption because the ActorContainer's `containerRef` would
// lose access to one of the ActorContainerRef's.
return GetActorResult {
.actor = actorRef->addRef(),
.ref = ref.addRef() };
}

// `hasClients()` will return true now, preventing cleanupLoop from evicting us.
return GetActorResult {
.actor = actorRef->addRef(),
Expand Down

0 comments on commit fb6ad2f

Please sign in to comment.