-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Summary
The README states that WebSocket connections automatically renew the activity timeout:
The Container also automatically renews the activity timeout when WebSocket messages are sent or received.
However, looking at the implementation, this doesn't appear to be the case. The container will sleep after sleepAfter expires, even with active WebSocket connections.
Analysis
renewActivityTimeout() is only called:
- Once in the constructor
- Once at the start of
containerFetch()(before the WebSocket upgrade) - During
startContainerIfNotRunning() - After
onActivityExpired()to prevent spam
After the WebSocket upgrade completes, tcpPort.fetch() proxies frames directly between client and container. The DO's JavaScript code never runs for individual WebSocket messages, so there's no opportunity to call renewActivityTimeout().
Reproduction
- Create a container with
sleepAfter = '1m' - Connect via WebSocket
- Keep sending/receiving WebSocket messages
- After 1 minute, the container is stopped despite the active WebSocket connection
Expected Behavior
Active WebSocket connections should keep the container alive, either by:
tcpPortnotifying the DO of WebSocket frame activity- Tracking active WebSocket connections and not expiring while any exist
- Some other mechanism to detect ongoing WebSocket traffic
Workaround
Currently the only workaround is to send periodic HTTP requests to manually refresh the activity timeout, which somewhat defeats the purpose of using WebSockets.