You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, using createTriplitHonoServer (from @triplit/server/hono) along with upgradeWebSocket (from @triplit/server/cloudflare) causes the websocket connection to be terminated directly within the DO (using server.accept()).
Ideally, this would instead use ctx.acceptWebSocket(server) to allow the workers runtime to terminate the websocket, allowing the worker to sleep during periods of inactivity on the websocket.
Messages would then need to be handled through the webSocketMessage class method instead of addEventListener on the websocket.
// Calling acceptWebSocket() informs the runtime that this WebSocket is to begin terminating
// request within the Durable Object. It has the effect of "accepting" the connection,
// and allowing the WebSocket to send and receive messages.
// Unlike ws.accept(), state.acceptWebSocket(ws) informs the Workers Runtime that the WebSocket
// is "hibernatable", so the runtime does not need to pin this Durable Object to memory while
// the connection is open. 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.
The text was updated successfully, but these errors were encountered:
Currently, using
createTriplitHonoServer
(from@triplit/server/hono
) along withupgradeWebSocket
(from@triplit/server/cloudflare
) causes the websocket connection to be terminated directly within the DO (usingserver.accept()
).Ideally, this would instead use
ctx.acceptWebSocket(server)
to allow the workers runtime to terminate the websocket, allowing the worker to sleep during periods of inactivity on the websocket.Messages would then need to be handled through the
webSocketMessage
class method instead ofaddEventListener
on the websocket.Build a WebSocket server with WebSocket Hibernation
The text was updated successfully, but these errors were encountered: