@@ -1734,7 +1734,7 @@ class Server::WorkerService final: public Service,
17341734 using AbortActorsCallback = kj::Function<void ()>;
17351735
17361736 WorkerService (ThreadContext& threadContext,
1737- kj::Own< const Worker> worker,
1737+ kj::Arc< Worker> worker,
17381738 kj::Maybe<kj::HashSet<kj::String>> defaultEntrypointHandlers,
17391739 kj::HashMap<kj::String, kj::HashSet<kj::String>> namedEntrypoints,
17401740 kj::HashSet<kj::String> actorClassEntrypoints,
@@ -1921,8 +1921,8 @@ class Server::WorkerService final: public Service,
19211921 observer = kj::refcounted<RequestObserverWithTracer>(
19221922 mapAddRef (workerTracer), kj::mv (streamingTailWorkers), waitUntilTasks);
19231923
1924- return newWorkerEntrypoint (threadContext, kj::atomicAddRef (* worker), entrypointName,
1925- kj::mv (props), kj::mv ( actor), kj::Own<LimitEnforcer>(this , kj::NullDisposer::instance),
1924+ return newWorkerEntrypoint (threadContext, worker. addRef ( ), entrypointName, kj::mv (props) ,
1925+ kj::mv (actor), kj::Own<LimitEnforcer>(this , kj::NullDisposer::instance),
19261926 {}, // ioContextDependency
19271927 kj::Own<IoChannelFactory>(this , kj::NullDisposer::instance), kj::mv (observer),
19281928 waitUntilTasks,
@@ -2081,16 +2081,15 @@ class Server::WorkerService final: public Service,
20812081 co_return ;
20822082 }
20832083 KJ_IF_SOME (m, manager) {
2084- auto & worker = a->getWorker ();
2085- auto workerStrongRef = kj::atomicAddRef (worker);
2084+ auto worker = a->getWorker ();
20862085 // Take an async lock, we can't use `takeAsyncLock(RequestObserver&)` since we don't
20872086 // have an `IncomingRequest` at this point.
20882087 //
20892088 // Note that we do not have a race here because this is part of the `shutdownTask`
20902089 // promise. If a new request comes in while we're waiting to get the lock then we will
20912090 // cancel this promise.
2092- Worker::AsyncLock asyncLock = co_await worker. takeAsyncLockWithoutRequest (nullptr );
2093- workerStrongRef ->runInLockScope (
2091+ Worker::AsyncLock asyncLock = co_await worker-> takeAsyncLockWithoutRequest (nullptr );
2092+ worker ->runInLockScope (
20942093 asyncLock, [&](Worker::Lock& lock) { m->hibernateWebSockets (lock); });
20952094 }
20962095 a->shutdown (
@@ -2375,7 +2374,7 @@ class Server::WorkerService final: public Service,
23752374 static constexpr uint16_t hibernationEventTypeId = 8 ;
23762375
23772376 actorContainer->actor .emplace (
2378- kj::refcounted<Worker::Actor>(* service.worker , actorContainer->getTracker (),
2377+ kj::refcounted<Worker::Actor>(service.worker . addRef () , actorContainer->getTracker (),
23792378 kj::str (idPtr), true , kj::mv (makeActorCache), className, kj::mv (makeStorage),
23802379 lock, kj::mv (loopback), timerChannel, kj::refcounted<ActorObserver>(),
23812380 actorContainer->tryGetManagerRef (), hibernationEventTypeId));
@@ -2466,7 +2465,7 @@ class Server::WorkerService final: public Service,
24662465 // LinkedIoChannels owns the SqliteDatabase::Vfs, so make sure it is destroyed last.
24672466 kj::OneOf<LinkCallback, LinkedIoChannels> ioChannels;
24682467
2469- kj::Own< const Worker> worker;
2468+ kj::Arc< Worker> worker;
24702469 kj::Maybe<kj::HashSet<kj::String>> defaultEntrypointHandlers;
24712470 kj::HashMap<kj::String, kj::HashSet<kj::String>> namedEntrypoints;
24722471 kj::HashSet<kj::String> actorClassEntrypoints;
@@ -3285,7 +3284,7 @@ kj::Own<Server::Service> Server::makeWorker(kj::StringPtr name,
32853284 }
32863285
32873286 jsg::V8Ref<v8::Object> ctxExportsHandle = nullptr ;
3288- auto worker = kj::atomicRefcounted <Worker>(kj::mv (script), kj::atomicRefcounted<WorkerObserver>(),
3287+ auto worker = kj::arc <Worker>(kj::mv (script), kj::atomicRefcounted<WorkerObserver>(),
32893288 [&](jsg::Lock& lock, const Worker::Api& api, v8::Local<v8::Object> target,
32903289 v8::Local<v8::Object> ctxExports) {
32913290 // We can't fill in ctx.exports yet because we need to run the validator first to discover
0 commit comments