Skip to content

Constructor renews the sleepAfter timer: any call into an evicted Container object extends the container's life #264

Open

Description

@Berik2001

Summary

sleepAfterMs lives only in memory, and the Container constructor calls renewActivityTimeout(). When the Durable Object has been evicted while its container is still running, any call that re-creates it, such as a custom RPC method that never touches the container, resets the sleep deadline to now + sleepAfter. Activity that never reached the container keeps it running, and billing, for another full sleepAfter.

Version

@cloudflare/containers 0.3.7

Mechanism (dist/lib/container.js, 0.3.7)

  • Constructor, inside blockConcurrencyWhile: await this.scheduleNextAlarm(); this.renewActivityTimeout(); (L355–360).
  • renewActivityTimeout() sets this.sleepAfterMs = Date.now() + sleepAfter (L770–773). The field is an in-memory instance field (sleepAfterMs = 0, L1024). The time of the container's last real activity is not persisted, so a new instance cannot tell how long the container has been idle.

Observation (staging, 2026-10-19, sleepAfter = '15m')

  1. Requests to the container at 00:15:20–00:15:52 UTC. The object's state, read by a read-only RPC method (state(), which only reads fields), showed bornAt 00:15:20, sleepAt 00:30:36.
  2. No traffic for 5 minutes.
  3. The same RPC at 00:20:53 showed bornAt 00:20:53 (the object had been re-created by that call) and sleepAt 00:35:53. The deadline had moved 5 minutes later, with no request to the container in between.

A deploy-time health check that calls into each object, or any periodic read-only RPC, can therefore keep containers awake indefinitely.

Expected

The time of the container's last activity survives re-creation of the object, for example in storage, alongside the alarm. A non-containerFetch call into the object should not count as container activity.

Activity

  1. Berik2001 commented on Oct 19, 2026

    @Berik2001
    Author

    The same effect in production, with no calls from us. Container application with sleepAfter = '15m', @cloudflare/containers 0.3.7. Times are UTC, 2026-10-19, taken from Workers Logs.

    • 05:55:50 is the last request to the container. It was a GET /api/health; the event is logged at its end, 05:58:49, with wallTimeMs 178713.
    • The deadline is therefore 06:10:50.
    • The Durable Object then reset itself:
      06:01:05 alarm  canceled
      06:01:31 alarm  exception
      06:01:31        Connection closed: this Durable Object instance is no longer active. Reconnect or retry the request.
      
    • The next alarms run on a new instance, and the stop comes at 06:01:05 + 15:00:
      06:16:04 alarm  Activity expired, signalling container to stop
      06:16:04 [container] [1] [INFO] Handling signal: term
      06:16:04 [container] [1] [INFO] Shutting down: Master
      

    The container ran 5 minutes 14 seconds past sleepAfter because the re-created instance's constructor called renewActivityTimeout(). Nothing reached the container after 05:55:50.

    For comparison, three later cycles on the same application, where the object was not re-created, stopped 15:00–15:01 after the last request: 06:17:27 → 06:32:27, 06:34:16 → 06:49:17, 07:05:39 → 07:20:40.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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