Skip to content

fix(realtime): wait for permission checks as long as the API database timeout - #15169

Merged
ArnabChatterjee20k merged 1 commit into
mainfrom
fix/realtime-permission-wait-api-timeout
Nov 2, 2026
Merged

ArnabChatterjee20k merged 1 commit into
mainfrom
fix/realtime-permission-wait-api-timeout

Conversation

@ArnabChatterjee20k

Copy link
Copy Markdown
Member

Issue / Description

Part of appwrite-labs/cloud#7177.

The bounded wait in Handler::verify() (#15086) used its own setting, _APP_REALTIME_PERMISSION_TIMEOUT (default 5 s). That number was unrelated to how long the database lets the check's query run:

  • With a 5 s wait and a longer query limit, the handler gave up and closed the affected connections unverified while the query was still allowed to finish and might have succeeded.
  • CE realtime's database handles set no query timeout (DatabaseFactory defaults to 0), so an abandoned query could run unbounded in the background.

The time worth waiting is exactly how long the database is allowed to answer, which for request-time work is the API limit.

Solution

  • verify() now waits APP_DATABASE_TIMEOUT_MILLISECONDS_API / 1000 seconds (15 s), the same limit an API request gives a query.
  • CE realtime's getConsoleDB() and getProjectDB() now set APP_DATABASE_TIMEOUT_MILLISECONDS_API on their database handles. The query is then killed when the wait ends, instead of running on unbounded. Cloud does the same in appwrite-labs/cloud#7181.
  • _APP_REALTIME_PERMISSION_TIMEOUT is removed from app/realtime.php, app/config/variables.php, docker-compose.yml and the console compose generator. Neither the cloud nor the infrastructure repo sets it.

Trade-off: a hung check can now hold the subscriber loop for up to 15 s instead of 5 s before it fails closed. Exceptions and coroutine-limit failures still fail closed immediately.

Tests

  • Wiring and config only: there is no new branch to unit-test.
  • tests/unit/Realtime, tests/unit/Docker (compose generator) and tests/unit/Platform/Modules/Installer: 262 tests pass.
  • Pint passes; php -l app/realtime.php is clean.

🤖 Generated with Claude Code

@luxor-code-review

luxor-code-review Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Stale _APP_REALTIME_PERMISSION_TIMEOUT env is silently ignored (realtime.php:621) — The permission-verification timeout changed from the configurable _APP_REALTIME_PERMISSION_TIMEOUT default of 5s to a fixed 15s (APP_DATABASE_TIMEOUT_MILLISECONDS_API / 1000 at app/realtime.php:621), and the variable was removed from every config surface with no deprecation shim.

This PR retires the realtime permission-verification timeout tuning knob and derives the timeout from the existing database query timeout instead.

Files Change
app/realtime.php Permission verification now uses a 15s window derived from APP_DATABASE_TIMEOUT_MILLISECONDS_API / 1000 instead of the removed _APP_REALTIME_PERMISSION_TIMEOUT (previously 5s)
app/config/variables.php Removes the _APP_REALTIME_PERMISSION_TIMEOUT variable definition and docs entry
docker-compose.yml Drops the env passthrough for the removed variable
apps/console/src/lib/docs/compose-generator/composeData.ts Removes the variable from the generated compose documentation data

Reviewed commit: 1ae94ea

@appwrite

appwrite Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

New Console

Project ID: new-console

Sites (1)
Site Status Logs Preview QR
 New Console
new-console
Ready Ready View Logs Preview URL QR Code

Tip

Silent mode disables those chatty PR comments if you prefer peace and quiet

@ghost

ghost commented Nov 2, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Realtime permission verification now uses the API database timeout, and realtime database handles apply that same timeout to their queries. The obsolete realtime-specific permission timeout setting is removed from the variable catalog and compose configuration.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
app/config/variables.php Removes the realtime-specific permission timeout variable.
app/realtime.php Applies the API database timeout to realtime database handles and permission verification.
apps/console/src/lib/docs/compose-generator/composeData.ts Removes the retired timeout variable from generated compose configuration.
docker-compose.yml Removes the retired timeout variable from the realtime service environment.

Reviewed 1ae94ea · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/appwrite/appwrite/@appwrite.io/console@15169

commit: 1ae94ea

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/realtime-permission-wait-api-timeout (after).

Metric Before After Change
🚀 Requests/sec 212.98 217.16 ⚪ +2%
⏱️ Latency P50 79.04 ms 79.66 ms ⚪ +0.8%
⏱️ Latency P95 196.5 ms 186 ms 🟢 -5.3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 79.66 186 13,680 217.16 -10.5
Account 155.4 281.43 720 12.1 +0.16
TablesDB 76.91 144.28 7,440 120.38 -4.49
Storage 74.35 165.8 3,600 59.99 -12.11
Functions 115.76 218.82 1,920 32.64 -9.09

Top API waits (after)

API request Max wait (ms)
account.prefs.update 496.47
account.name.update 480.36
functions.variables.update 428.84
functions.delete 402.15
tablesdb.rows.increment 373.08

@ArnabChatterjee20k
ArnabChatterjee20k merged commit e646eec into main Nov 2, 2026
76 of 77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant