simolus3 opened PR #14392 from simolus3:idle-process-timeout to bytecodealliance:main:
wasmtime servecan inherit sockets from systemd, which is convenient to start it lazily when needed. Since socket activation is attractive for services that don't receive continuous traffic, it would also be nice to stop after a while of inactivity. systemd then continues to monitor the socket and will restart the service on the next request.This adds the
--idle-process-timeoutoption: After the first connection has been opened [^1], a task monitors the amount of active connections. Once no connections are detected for the idle timeout, we start a graceful shutdown.This operates on a connection level, meaning that idle keep-alive connections keep the process alive. I think this is reasonable for a service, as it's still serving something. Most reverse-proxies have options to reduce idle connection times.
There's an inherent race as it's possible for the idle shutdown to fire just after the connection has been accepted. This means that the connection still gets served while no further connections would be accepted until the process restarts. Not ideal, but this should also be rare in practice. No unaccepted connections are lost because systemd immediately restarts the service, this just increases latency.
Discussed in https://github.com/bytecodealliance/wasmtime/issues/14289#issuecomment-5586772709.
[^1]: Waiting for the first connection avoids a race in tests where the child could technically exit before the test host.
simolus3 requested wasmtime-core-reviewers for a review on PR #14392.
simolus3 requested dicej for a review on PR #14392.
:thumbs_up: alexcrichton submitted PR review:
Thanks!
alexcrichton has enabled auto merge for PR #14392.
alexcrichton added PR #14392 Serve: Add --idle-process-timeout option to the merge queue.
:check: alexcrichton merged PR #14392.
alexcrichton removed PR #14392 Serve: Add --idle-process-timeout option from the merge queue.
Last updated: Oct 11 2026 at 04:10 UTC