Hello, I'm looking at using Durable Objects as a Websocket server. I'm a bit confused by the [Hibern

Hello, I'm looking at using Durable Objects as a Websocket server. I'm a bit confused by the Hibernate API, and this SO post.

Since DurableObjects are basically in-memory classes, their long-term state cannot be guaranteed - especially in cases which involve the Hibernation API. When the DurableObject hibernates, the existing websocket connections are kept alive "outside" of the class - and when one wakes up, the Workers runtime will reinstantiate the DurableObject with a new state.

My confusion is that I thought the whole point of DO was to be a "stateful worker". But this comment seems to claim the opposite (might just be bogus). That said, the docs also claim that:

// ... During periods of inactivity, the Durable Object can be evicted
// from memory, but the WebSocket connection will remain open. If at some later point the
// WebSocket receives a message, the runtime will recreate the Durable Object
// (run the constructor) and deliver the message to the appropriate handler.

Am I misunderstanding the point of DOs? Or is this just an edge case with the hibernate API and I should use serializeAttachment / deserializeAttachment to store persistent state?
Was this page helpful?