Repository navigation
fix: remove orphaned runtimes when the executor starts - #262
Merged
Merged
Conversation
loks0n
approved these changes
Oct 12, 2026
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When the executor starts, remove any runtime containers it doesn't track, before it does anything else.
The issue
Self-hosted users report function containers stuck in a restart loop:
The gaps grow 1s, 2s, 3s, 6s, 13s, 26s, 51s, then hold at 60s. That's Docker's restart backoff for a container that exits right after starting, and it never ends.
1. Runtimes restart forever, and their code lives in a host directory
Appwrite creates every function runtime with
restartPolicy: 'always':The runtime's
/tmp, which holdscode.tar.gz, is a bind mount of a directory on the executor host:2. The executor forgets its runtimes when it restarts
Runtimes are tracked only in an in-memory
Runtimestable. When the executor restarts (an upgrade,docker compose up, a crash or a reboot), the table starts empty, but the runtime containers keep running because ofrestart: always.Nothing reconciles them on startup.
onStartsets up networks, pulls images and starts maintenance. The SIGTERM cleanup was removed in c206e60 (it notedThis doesn't actually work), andDocker::cleanup()has had no callers since.3. Maintenance deletes the code of untracked runtimes that are still running
The orphan keeps serving, because its code was already extracted into the container. The damage stays hidden until the container next exits on its own (a crash, an OOM kill, a Docker daemon restart or a host reboot). Docker then starts it again with an empty
/tmp, and it loops forever.Timeline
Reproduced end to end
Appwrite 2.4.0 with executor 0.29.0 (
OPR_EXECUTOR_MAINTENANCE_INTERVAL=15):RestartPolicy=alwaysand the mount/tmp/exc1-repro-…/src -> /tmp.docker restart exc1. The runtime keeps running.[Maintenance] Removed /tmp/exc1-repro-6accabeeaebb5b66e83c., while the container is stillUp.Code path /tmp/code.tar.gz not foundat 09:47:21, :21, :21, :22, :24, :27, :34, :47 …, andRestartCount=9after 50s.(A
docker killdoesn't trigger the loop, because Docker treats it as a manual stop and skips the restart policy.)Second bug, found by the test: the executor looks up the wrong container as itself
Docker's
namefilter matches substrings. With hostnameexecutorand an orphan namedexecutor-test-orphan,[0]was the orphan, soNetwork::setup()tried to attach the orphan to the runtimes network:Production has the same naming pattern (executor
exc1, runtimesexc1-…). Removing orphans before this lookup means only the executor's own container can match on startup.Changes
Docker::cleanup(), which nothing called and which this replaces.Tests
testRestartRemovesOrphanedRuntimes(e2e) creates a runtime withrestartPolicy: always, runsdocker restarton the executor container, waits for/v1/health, and asserts the runtime container is gone.main, it fails: the orphan container97d2b59b0b38still exists.[Maintenance] Removed 1/1 orphaned runtimes.and attaches its own container to the network.composer format:check,analyze,refactor:checkand the unit tests (37) pass locally.