Repository navigation
fix(cache): count the error behind a redis write reported as false - #14641
Conversation
Redis::save(), saveMany() and saveWithLease() catch every Throwable and return false, so a write that misses its read deadline looks the same as one Redis refused. In Appwrite Cloud that false reached utopia-php/database as "Failed to register document cache owner". Nothing recorded why, which led to a wrong out-of-memory diagnosis: Dragonfly reported zero OOM rejections. The adapters now pass the cause to a recordWriteFailure() hook on Leasable. Redis\Multiplexing, the adapter Cloud runs and the one that already reports telemetry, counts it as cache.redis_multiplexing.write.failures, tagged with the operation and the short error class. The write still returns false, so callers see the same behaviour. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
This PR extends the Redis cache adapter with a multiplexing mode, a leasable write path, and write-failure telemetry counters, adding an E2E test for read deadlines.
One medium-confidence robustness issue remains in the telemetry instrumentation path, noted as an inline comment. Reviewed commit: 2bc2913 |
🟢 Tier S · Ready to merge
Redis write exceptions that are converted to Latest changes: The deadline test now exercises
📂 Walkthrough · 4
✅ Fixed since the last review · 1
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
There was a problem hiding this comment.
Adds lease-aware and multiplexed Redis cache adapters with write-failure telemetry counters, plus an E2E deadline test; one robustness gap found in the telemetry instrumentation path.
Key findings
- 🟡 Guard
recordWriteFailureagainst throwing telemetry — Multiplexing.php:145
| #[\Override] | ||
| protected function recordWriteFailure(string $operation, Throwable $error): void | ||
| { | ||
| $this->getWriteFailures()->add(1, [ | ||
| 'operation' => $operation, | ||
| 'error' => new \ReflectionClass($error)->getShortName(), | ||
| ]); | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Guard recordWriteFailure against throwing telemetry
recordWriteFailure runs inside every catch (Throwable) write handler and calls $this->telemetry->createCounter(...) / Counter::add(...) unguarded (packages/cache/src/Adapter/Redis/Multiplexing.php:145-152). If the telemetry adapter throws — a failing exporter, or an error on the lazy createCounter first use — the exception escapes save, saveMany, and saveWithLease, breaking the documented contract of reporting a write failure as false. A telemetry outage would then turn silent cache-write degradation into hard exceptions for callers, since Cache::save does not catch adapter exceptions.
📋 Prompt for AI Agents
In packages/cache/src/Adapter/Redis/Multiplexing.php around lines 145-152, wrap the body of recordWriteFailure (the getWriteFailures()->add(...) call) in a try/catch (Throwable) that ignores telemetry errors. The surrounding save/saveMany/saveWithLease catch blocks must still reliably return false even when the telemetry adapter throws.
There was a problem hiding this comment.
Leaving this unguarded on purpose. Every instrument in this package records without a guard, including the cache.operation.duration histogram that Cache::save() records in a finally on this same failure path. The telemetry adapters (OpenTelemetry, None, Test) do not throw on add(). Guarding only this one call would not protect the write path and would be inconsistent with the rest of the package.
There was a problem hiding this comment.
The consistency argument is noted, but it cuts both ways: if any telemetry adapter ever throws (network-backed exporters, misconfigured test doubles, future adapters), this method will convert a cache write failure into an unhandled exception on the caller's stack. The cache.operation.duration histogram recorded in finally shares the same risk, but that does not reduce the risk here — it multiplies it. Guarding recordWriteFailure with a try/catch (Throwable) is a one-line change that costs nothing and preserves the documented false-return contract unconditionally. The finding remains open.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
The failure counter test only drove save(). saveMany() and saveWithLease() go through their own catch blocks and operation labels, so a missing hook or wrong label there would have passed unnoticed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
Redis::save()/saveMany(),Redis\Multiplexing::save()/saveMany()andLeasable::saveWithLease()swallow everyThrowableand returnfalse. They now pass the cause to arecordWriteFailure()hook onLeasable.Redis\Multiplexingcounts it ascache.redis_multiplexing.write.failures, tagged withoperationanderror(the short exception class, e.g.TimeoutException). The return values are unchanged.Why
In Appwrite Cloud, a multiplexed HSET that missed its 100ms read deadline reached utopia-php/database as
Failed to register document cache owner. Nothing recorded why, so it was first blamed on Redis memory, but Dragonfly showed zero OOM rejections. With this counter, the next slow or refused write says which it was. The database side of the fix is utopia-php/database#1041.Tests
MultiplexingDeadlineTest::testAWriteThatMissesItsDeadlineCountsItsCause: pauses the server, assertssave()returns false, and asserts the counter recorded['operation' => 'save', 'error' => 'TimeoutException']. It fails without the change.bin/monorepo check cache --linkedpasses (Pint, PHPStan max, Rector).🤖 Generated with Claude Code