Skip to content
Commit Detail

Commit 976e26c

Author
Gregory Anders <ganders@cloudflare.com> 2026-01-08 15:20:02 -0600
Parents
2b71448
Tree
d7db088
CC-6219: Implement setInactivityTimeout in ContainerClient (#5491)

* Implement setInactivityTimeout in ContainerClient

setInactivityTimeout allows a container to outlive its associated actor.
The current implementation tightly couples the lifetime of the container
client to the lifetime of the actor, so that the ContainerClient is
always destroyed whenever the actor is destroyed.

To fix this we make ContainerClient reference counted and provide a
reference to the actor. Whenever setInactivityTimeout is called we add a
reference to the client. If the actor shuts down, the remaining
reference keeps the container alive until the timeout expires. If
setInactivityTimeout was never called then there is no remaining
reference, and the container shuts down when the actor does.

We also implement the ability for an actor to reconnect to an already
running container when it restarts. We do this by maintaining a map of
containerId->ContainerClient in the ActorNamespace. This map does not
hold a reference to the ContainerClient: only actors and the inactivity
timeout promise hold references to ensure we do not leak resources by
holding a reference indefinitely. Whenever an actor starts it consults
the map to see if a ContainerClient already exists. If it doesn't we
create one and add it to the map.

In order to clear entries from the map when a ContainerClient is
destroyed we provide a callback function (`cleanupCallback`) to the
ContainerClient which is run when ContainerClient is destroyed.

* Add test for setInactivityTimeout

Files changed