Repository navigation
Description
π Reproduction steps
Self-hosted 2.0.0 (PostgreSQL). Any function that calls back into the Appwrite API β the normal server-function pattern β executed synchronously with a little concurrency:
- Deploy a function that makes a few API calls back to Appwrite (e.g.
tablesDB.listRows) using a server SDK and an API key. - Fire N synchronous executions at once:
for i in $(seq 4); do
curl -s -X POST "$ENDPOINT/v1/functions/$FN/executions" \
-H "X-Appwrite-Project: $PROJECT" -H "X-Appwrite-Key: $KEY" \
-H 'Content-Type: application/json' \
-d '{"body":"{}","async":false}' &
done; wait- With N as low as 4, every execution fails at the SDK's client timeout. The same work run with
"async": truealways succeeds, because the functions worker runs those one at a time.
π Expected behavior
Concurrent synchronous executions complete. A function calling back into the API should not be able to starve the server that is waiting for it.
π Actual behavior
All concurrent executions hang until the calling SDK's timeout and then fail. The API log shows:
WARNING Server::timer_callback() (ERRNO 9007): No idle worker is available
Meanwhile the API answers other requests (pings, keyed row reads, even from inside the runtime container) in single-digit milliseconds, and no row-list request in the API's own log exceeds 100 ms. The requests never reach a worker.
π Prior report
This looks like the same failure as #5629 "Appwrite main container freezes when executing cloud-functions" (closed as completed), where the last comments report it still reproducing and the offered workaround is to run a second Appwrite API container and point function callbacks at it. That workaround is consistent with the analysis below: it works because the function's callbacks then land on a server whose workers are not the ones blocked waiting for the executor. The root cause below explains why, and needs no second container.
π² Root cause
app/http.php builds the Swoole server with a plain settings array:
$swoole = new Server(
host: "0.0.0.0",
port: System::getEnv('PORT', 80),
settings: [
Constant::OPTION_WORKER_NUM => $totalWorkers,
Constant::OPTION_HTTP_COMPRESSION => false,
Constant::OPTION_PACKAGE_MAX_LENGTH => $payloadSize,
Constant::OPTION_OUTPUT_BUFFER_SIZE => $payloadSize,
],
resources: $container,
);utopia-php/http's Adapter\Swoole\Server accepts Mode|array. Because an array is passed, none of the tuned presets in Adapter\Swoole\Mode apply, so Swoole's own defaults govern β in particular hook_flags is unset (no runtime hooks) and dispatch_mode stays at the default.
That combination produces the deadlock:
- A synchronous execution blocks its worker for the whole run, waiting on the executor over plain
curl. Withouthook_flags, that call cannot yield. - The function's own API calls arrive as a burst while those workers are blocked.
- With no idle worker, the reactor queues them onto workers that are themselves blocked β waiting for exactly those requests.
- Both sides wait until the caller's timeout.
This is unchanged from 2.0.0-rc.2: app/http.php is byte-identical across rc.2, rc.3 and 2.0.0, and utopia-php/http is still pinned at 2.0.0-rc25.
Things that do not fix it, for the record: raising _APP_WORKER_PER_CORE, raising the connection-pool size, dispatch_mode => 3 alone, and enable_coroutine => false (which breaks Appwrite's own CoroutineLock). max_concurrency also is not the answer β it throttles the whole server.
π§ Proposed fix
Pass a Mode (the adapter already defines tuned presets), or at minimum set the hook flags in app/http.php:
Constant::OPTION_HOOK_FLAGS => SWOOLE_HOOK_ALL,The shipped Swoole build has curl-native and coroutine_pgsql enabled, so blocking calls become coroutine-aware and a synchronous execution yields its worker instead of holding it.
With that one option added (plus dispatch_mode => 3), on the same instance and hardware:
| concurrent sync executions | before | after |
|---|---|---|
| 4 | 4/4 fail at the client timeout | all succeed, 0.12 s |
| 12 | 12/12 fail | all succeed, 0.05 s each |
| 30 | 30/30 fail | all succeed, ~2 s median |
π₯ Specification
- Version: 2.0.0 (self-hosted, also reproduced on 2.0.0-rc.2 and rc.3)
- Database: PostgreSQL 18
- Swoole 6.2.2 (
curl-nativeenabled,coroutine_pgsqlenabled) - Runtime of the calling function: Go, but the mechanism is runtime-independent
Activity
nk0273926 commentedon Sep 9, 2026
Hi, Iβd like to work on this issue. Iβve reviewed the root cause and would like to reproduce it locally, implement the Swoole configuration fix, and add tests. Is it okay if I take this up?
AlimFreight commentedon Sep 10, 2026
@nk0273926 β reporter here, and glad to see someone picking this up. Not a maintainer, so the assignment isn't mine to give, but here is everything I have so it saves you the reproduction work.
The one-line cause.
app/http.phppasses a bare settings array to the Swoole server, so utopia-http'sModepresets never apply andhook_flagsis therefore never set. WithoutSWOOLE_HOOK_ALL, a synchronous function execution blocks its worker inside curl instead of yielding, callbacks queue behind it, and you getNo idle worker is available. The file is byte-identical between 2.0.0-rc.2 and 2.0.0, so it's not a recent regression.Reproducing it. A function whose handler makes an HTTP call back into Appwrite (any SDK call) is enough; fire executions concurrently past the worker count. Ours surfaced as a hard 15-second
context deadline exceededon every dashboard read β worth knowing the symptom presents as a timeout, not an obvious deadlock, so it's easy to misattribute to the database or the network. I chased stale keep-alives and worker caps first; both were wrong.What we run in production today, patched in-container since 2026-09-04 and stable since:
Three things that cost us time and might save you some:
_APP_WORKER_MAX_COROUTINESis the per-worker pool size, and the pool math inregisters.phpismax(1, int((151/14)/workers))thenmax(poolSize, _APP_WORKER_MAX_COROUTINES). We run 32 on the api service; at 16 we hit pool timeouts under load.max_concurrencylooks like the right knob and is not β it's a server-wide throttle and produced 503s. Don't reach for it.enable_coroutine=falsebreaks Appwrite's ownCoroutineLock. Also a dead end.Happy to test a PR against a real self-hosted 2.0.0 instance (PostgreSQL 18, 12 workers, Go functions) β it reproduced reliably here before the patch and hasn't recurred since.
nk0273926 commentedon Sep 12, 2026
Thanks for sharing the detailed root cause and reproduction steps β this is really helpful. Iβll focus on the
hook_flagsanddispatch_modeconfiguration inapp/http.php, then verify the fix with concurrent synchronous function executions.Iβll also keep the coroutine pool size and the
max_concurrency/enable_coroutinecaveats in mind. Iβll share the proposed change here before opening a PR. Thanks again for offering to test it against a real instance!HarshMN2345 commentedon Sep 22, 2026
This has been fixed on main. Closing as completed.