Skip to content

fix(realtime): skip the project check when this pod holds no connections for it - #15168

Merged
ArnabChatterjee20k merged 3 commits into
mainfrom
fix/realtime-project-check-without-connections
Nov 2, 2026
Merged

ArnabChatterjee20k merged 3 commits into
mainfrom
fix/realtime-project-check-without-connections

Conversation

@ArnabChatterjee20k

@ArnabChatterjee20k ArnabChatterjee20k commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Issue / Description

Investigation: appwrite-labs/cloud#7179

projects.* events (transfer update.team, project-wide sessions.delete) are console events, so they are published in the console region only. On 2026-11-01 17:15:43 UTC, all three FRA realtime pods received projects.protiva.update.team for an SGP project. Each one failed the permission check with Pool 'database_db_sgp1_self_hosted_0_0' not found.

The cause is revalidateProject(). It starts the coroutine and the database check before checking whether this pod holds any connection for the project. checkProject() then resolves the project's database first, which in another region throws. FRA held no protiva connections (realtime.closed=0 on every pod), so the check was useless there. #15086 caught the exception. Before #15086, the same event would have frozen FRA realtime.

Solution

  • revalidateProject() returns before verify() when the pod holds neither connections nor console tails for the project. There is nothing to re-check, so it skips the coroutine and both database lookups.
  • checkProject() resolves the project database lazily, only for a session or impersonator connection that needs it. Console tails are re-authorized from the project document alone, so the console region can still end a tail on a project hosted in another region without that region's pool.

Not in this PR: the region that holds the project's own connections never receives these events. That is tracked in appwrite-labs/cloud#7179 (Finding 3).

Tests

  • New HandlerTest::testSkipsTransferOfProjectWithoutConnectionsOnThisPod sends a projects.remote.update.team event to a handler with no connections.
    • Before the fix, the handler enters verify(), runs the coroutine and database check, and the PHPUnit process dies (exit 255).
    • After the fix, the result is no_subscriber and no failure is counted.
  • The existing e2e RealtimeConsoleTailTest::testTailEndsWhenProjectIsTransferred covers the tail path: a console tail with no project connections, then a transfer.
  • tests/unit/Realtime: 61 tests pass.
  • Pint and PHPStan pass on the changed files.

🤖 Generated with Claude Code

@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟠 1 high

💬 Inline comments (1)


This PR short-circuits revalidateProject in the Realtime event handler when a project has no live connections on the current worker, avoiding wasted sweep work for cross-region events. The new guard is unit-tested for the empty-connection case.

Files Change
src/Appwrite/Realtime/Event/Handler.php Adds an early return before the project revalidation sweep when getProjectConnections is empty.
tests/unit/Realtime/Event/HandlerTest.php Adds a unit test covering the skip path when no project connections exist.

Reviewed commit: 4292899

@ghost

ghost commented Nov 2, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The failure path now removes project tails without affecting tails for other projects, and the new test verifies that behavior.

Project permission checks are skipped when a realtime pod has neither project connections nor console tails, and the project database is resolved only when a session-backed connection needs a user lookup. When verification fails, the handler now detaches local tails for that project as well as failing closed for affected connections.

Latest changes: The latest commit detaches every local project tail when permission verification fails and adds a registry regression test for that cleanup.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
src/Appwrite/Realtime/Event/Handler.php Skip irrelevant project checks, defer project database resolution, and detach project tails on verification failure.
tests/unit/Realtime/Event/HandlerTest.php Cover a project event received by a pod with no local connections.
tests/unit/Realtime/EventTailRegistryTest.php Verify project reauthorization detaches tails when no read roles are available.

Reviewed the commits since ca3e73b · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

ghost
ghost previously requested changes Nov 2, 2026

@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 F · 1 blocking finding to address. Summary

Comment thread src/Appwrite/Realtime/Event/Handler.php Resolved

@luxor-code-review luxor-code-review Bot 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.

Adds an early-return guard in the Realtime event handler so permission-revalidation sweeps are skipped for projects with no connections on the worker.

Key findings

Comment thread src/Appwrite/Realtime/Event/Handler.php Resolved
@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-project-check-without-connections (after).

Metric Before After Change
🚀 Requests/sec 204.48 210.67 ⚪ +3%
⏱️ Latency P50 82.38 ms 81.45 ms ⚪ -1.1%
⏱️ Latency P95 205.38 ms 196.28 ms ⚪ -4.4%
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 81.45 196.28 13,566 210.67 -9.09
Account 153.54 316 714 11.8 +2.66
TablesDB 78.2 143.04 7,378 117.86 -14.52
Storage 75.78 173.9 3,570 58.37 -2.69
Functions 120.39 242.66 1,904 31.72 +3.48

Top API waits (after)

API request Max wait (ms)
account.name.update 467.29
functions.variables.create 441.53
account.prefs.update 425.53
functions.variables.update 377.25
account.get 373.4

@ghost
ghost dismissed their stale review November 2, 2026 08:23

The findings that requested changes are resolved. See the summary comment for what is still open.

ghost
ghost previously requested changes Nov 2, 2026

@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 B · 1 blocking finding to address. Summary

Comment thread src/Appwrite/Realtime/Event/Handler.php Resolved
@ghost
ghost dismissed their stale review November 2, 2026 08:27

The findings that requested changes are resolved. See the summary comment for what is still open.

@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

@ArnabChatterjee20k
ArnabChatterjee20k merged commit b8f9ce2 into main Nov 2, 2026
36 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