Skip to content

WebSocket connections don't renew activity timeout - container sleeps despite active connections #147

@danielbodart

Description

@danielbodart

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

  1. Create a container with sleepAfter = '1m'
  2. Connect via WebSocket
  3. Keep sending/receiving WebSocket messages
  4. After 1 minute, the container is stopped despite the active WebSocket connection

Expected Behavior

Active WebSocket connections should keep the container alive, either by:

  1. tcpPort notifying the DO of WebSocket frame activity
  2. Tracking active WebSocket connections and not expiring while any exist
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions