Repository navigation
Description
Issue 01: Async GC — gc_status()['threshold'] grows by 10k after every root-buffer-full collection and never resets (long-running servers hit memory_limit)
Repo: true-async/php-async (extension) / true-async/php-src (branch php-8.6.0-trueasync-0.9.6)
Severity: high for long-running HTTP servers
Summary
After every collection triggered by the root-buffer-full condition, gc_status()['threshold'] grows by ~10k (10001 → 20001 → 30001 → …) and never resets. In sync mode (before any stream I/O) the threshold stays at 10001 — same as stock PHP. The growth makes collection intervals and the memory amplitude grow linearly, so a long-running server eventually hits memory_limit.
Calling gc_collect_cycles() explicitly keeps the threshold at 10001 and memory flat.
Environment
- PHP 8.6.0-dev (ZTS), TrueAsync ABI v0.24.0, async ext v0.9.4
- Windows (VS2026 build, Aug 6 2026) and Linux (zig static build, Aug 11 2026) — identical behavior on both
- Stock PHP 8.5.9 (no true_async) as control — clean
Repro (self-contained, no vendor required)
In bin/gc_repro/:
threshold_cli.php <sync|async> [cycles] [every] [yield]— CLI: allocates cycles;sync= no stream I/O (GC stays sync),async= afile_get_contents/fopencall flips GC to async modethreshold_http.php <port> <cycles_per_request> <explicit_gc=0|1>— minimal TrueAsync HTTP server, cycles per requestsweep_client.php <port> <n> <interval>— client for the HTTP repro
php threshold_cli.php async 20000 10000 0 # prints gc_status() before/after each collection
Results matrix
| Scenario | threshold | gc runs | usage |
|---|---|---|---|
| CLI sync (TrueAsync, Win+Linux) | stable 10001 | 3 | 2.5–4.5 MB, sawtooth every 10k (normal) |
| CLI async (TrueAsync, Win+Linux) | 10001 → 40001 | 0 | 2.5 → 16.85 MB monotonic |
CLI async + Async\delay(1) after each print |
10001 → 20001 → 30001 | 2 (collects everything, collected=40000) | 0.7 MB — threshold grows even while GC works |
| CLI async (stock PHP 8.5.9, control) | stable 10001 | 3 | normal sawtooth — growth is TrueAsync-specific |
| HTTP auto, 500 cycles/req, 2s interval | 10001 → 20001 → 30001 | collections at req 20 and 34 | amplitude 0.5→16 MB, then 0.6→32 MB |
| HTTP auto back-to-back 0.05s | 10001 → 20001 | 1 | same |
| HTTP auto, 30 parallel | 30001 after 70 reqs | 2 | same |
HTTP explicit (gc_collect_cycles()/req) |
stable 10001 | 1/request | flat 0.52 MB (Win) / 0.49 MB (Linux) |
Real-server observation: the 10k root-buffer threshold was crossed at ~12–13 requests (~800 roots/request, ~12 MB); OOM at 200–400 requests ≈ the 4th–5th cycle of the growing amplitude.
Expected vs actual
- Expected: after a root-buffer-full collection, the threshold returns to its base value (10001) — as in stock PHP and in sync mode.
- Actual: the threshold permanently grows by ~10k per such collection; the async GC coroutine then runs collections less and less often; memory amplitude grows linearly; long-running servers OOM.
Question
Is the threshold growth intended behavior of the async-GC scheduler, or a bug? If intended, how is a long-running process supposed to bound its memory (the docs recommend against manual gc_collect_cycles())?
Docs reference: https://true-async.github.io/en/architecture/async-gc.html
Activity
Runnin4ik commentedon Aug 15, 2026
Repro kit (scripts): https://gist.github.com/Runnin4ik/a1990df9abfa5218c79d6c940eddfd99
Key files:
threshold_cli.php,threshold_http.php,sweep_client.php#234: cover the threshold contract from both ends
#234: make the two stable-threshold tests say what else must hold
Merge pull request #243 from true-async/234-gc-threshold-tests
test(gc): drop the run count from 015 instead of restating it (#234)
Merge pull request #249 from true-async/234-gc-runs-not-a-contract