Repository navigation
Cap in-flight MQTT permission checks - #15093
ArnabChatterjee20k wants to merge 1 commit into
Conversation
A timed-out revoke or unsubscribe check is never reaped: it keeps its coroutine and database connection until the read returns, so a slow database could drain the pool. Checks in flight are now capped per worker at half the console database pool (at least 1); past the cap the event fails closed at once, recorded as mqtt.verification = check_limit with an attached error. Revoke and unsubscribe share one bounded verify() step. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. 🟡 1 medium 📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Thrown permission check fails open, keeping access · Handler.php:67–72 · // src/Appwrite/Mqtt/Event/Handler.php
67 if ($outcome instanceof \Throwable) {
68 $span->set('mqtt.verification', 'failed');
69 $span->setError($outcome);
70
71 return;
72 }When the permission check throws, the revoke handler treats the error as a span annotation only: it sets This change replaces the ad-hoc coroutine/channel scaffolding inside
Reviewed commit: a83e103 |
🟢 Tier S · Ready to merge
This change adds a shared in-flight limit for MQTT revoke and unsubscribe permission checks, derived from the console database pool size. Checks beyond the limit fail closed immediately, and timed-out checks retain their slot until the underlying coroutine completes. The unit tests cover cap behavior, continued delivery, and slot release.
📂 Walkthrough · 3
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
Stacked on #15085. When a revoke or unsubscribe permission check times out, the broker fails closed and moves on, but nothing reaps the check. It keeps its coroutine and its database pool connection until the read returns. The pool per worker is small, so under a slow database the stuck checks could drain it and starve everything else on the worker.
Tracking: appwrite-labs/cloud#7108
Solution
verify()step inAppwrite\Mqtt\Event\Handler, which counts the checks in flight on the worker.go()and down in the child'sfinally. A stuck check keeps its slot until its read returns, so stuck checks can never hold more than the cap.expel()for revoke anddrop()for unsubscribe. The span recordsmqtt.verification = check_limitwith an attachedRuntimeException("Permission verification skipped: check limit reached"), the same exception choice as the coroutine-limit path. A legitimate user reconnects and CONNECT re-authenticates them.app/mqtt.phpwith$register->get('pools')->get('console')->size. There is no new environment variable.Limits
app/init/registers.phpsplits 151 / 15 connections across CPU × 6 workers, which rounds down to 1. So the cap is also 1. At that size one stuck check already holds the whole pool, and the cap can't keep a connection free for other work.Tests
testChecksPastTheCapFailClosedImmediatelyintests/unit/Mqtt/Event/HandlerTest.phpruns in its own process, like the other stuck-check tests.NOT_AUTHORIZED, and recordcheck_limitwith the error.verified.Red on #15085's head: the second revoke waited out the full timeout (0.202s against a 0.2s timeout) and recorded
timed_out, starting a second stuck check, instead of failing fast withcheck_limit.Green on this branch:
tests/unit/Mqttpasses (91 tests).🤖 Generated with Claude Code