From 0f9f997a64e444239a985d274000abd27d08b101 Mon Sep 17 00:00:00 2001 From: Milan Miladinovic Date: Mon, 19 Jun 2023 16:58:13 -0400 Subject: [PATCH] Hardcode ws hibernation event type in workerd When attempting to use the websocket hibernation api while running `wrangler dev`, we saw `a.getHibernationEventType() != nullptr` errors pop up because the hibernation event ID is defined in our internal codebase. Note that this change only affects server.c++, which durable objects does not rely upon in production. This also does not enable the actual hibernation of websockets/DOs, it's only a step towards getting hibernatable websocket events to deliver locally. --- src/workerd/server/server.c++ | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/workerd/server/server.c++ b/src/workerd/server/server.c++ index cb8a181eb67..0ddd5bade4c 100644 --- a/src/workerd/server/server.c++ +++ b/src/workerd/server/server.c++ @@ -1394,10 +1394,13 @@ public: auto loopback = kj::refcounted(*this, kj::str(id)); Worker::Lock lock(*service.worker, asyncLock); + // We define this event ID in the internal codebase, but to have WebSocket Hibernation + // work for local development we need to pass an event type. + static constexpr uint16_t hibernationEventTypeId = 8; auto newActor = kj::refcounted( *service.worker, nullptr, kj::str(id), true, kj::mv(makeActorCache), className, kj::mv(makeStorage), lock, kj::mv(loopback), - timerChannel, kj::refcounted(), nullptr, nullptr); + timerChannel, kj::refcounted(), nullptr, hibernationEventTypeId); // If the actor becomes broken, remove it from the map, so a new one will be created // next time.