Repository navigation
fix(realtime): never let an exception reach the pub/sub subscribe loop - #15166
Conversation
With an exception pending, phpredis keeps reading pub/sub messages but zend_call_function() refuses to run the callback, so the worker silently stops delivering until it restarts. handle() still ran its received counter and decode before its try, and the entrypoint built and logged the event span outside any try. handle() now runs everything inside its guard (counting a failure cannot throw either), and the subscribe callback catches anything that still escapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No issues found — approved ✅. This PR wires realtime event processing through a new
Review found no defects meeting the reporting threshold; the change is a clean, well-tested refactor of the realtime event path. Reviewed commit: ab73d4a |
🟢 Tier S · Ready to merge
The realtime event handler now guards event counting and decoding alongside the existing processing path, and protects failure telemetry from throwing out of the handler. The pub/sub callback also catches exceptions from event handling and span processing, with a regression test covering a telemetry failure during receipt counting.
📂 Walkthrough · 4
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Issue / Description
Root cause: appwrite-labs/cloud#7177
The FRA realtime outages of 2026-10-28, 10-29 and 10-30 were caused by an exception reaching the phpredis
subscribe()loop. With an exception pending, phpredis 6.3.0 keeps reading pub/sub messages, but PHP'szend_call_function()returnsSUCCESSwithout running the callback (Zend/zend_execute_API.c: "we would result in an unstable executor otherwise"), and phpredis only stops on a non-SUCCESS return. The worker then reads and drops every event,subscribe()never returns, nothing is logged, and only a restart recovers it. Reproduced on staging with the prod binaries (PHP 8.5.12, phpredis 6.3.0, Swoole 6.2.3); details in the issue.#15086 put the event handling behind a
try/catch, but two paths still reach phpredis:Handler::handle()counts the event and decodes it before itstry.app/realtime.phpbuilds the event span, callsshouldLog()and logs the span outside anytry.An exception on either path freezes the worker the same way.
Solution
Handler::handle()runs everything inside its guard, including the received counter and the decode. Counting the failure is guarded too, so a broken telemetry call cannot throw past it.Throwablethat still escapes and logs it, so nothing can reach phpredis.Tests
HandlerTest::testNeverThrowsWhenTelemetryFails: the received counter throws (aThrowingCounterfake). Before the fix the exception escapedhandle()atHandler.php:71(red); after it,handle()returnsfailedwith the error and counts the failure at thedecodestage (green).tests/unit/Realtime: 61 tests pass.🤖 Generated with Claude Code