Skip to content

refactor(database): drop Swoole PDOProxy, construct Utopia\Database\PDO directly - #12616

Merged
abnegate merged 1 commit into
1.9.xfrom
fix/drop-pdoproxy
Jun 19, 2026
Merged

abnegate merged 1 commit into
1.9.xfrom
fix/drop-pdoproxy

Conversation

@abnegate

@abnegate abnegate commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Depends on utopia-php/database#896. Composer is pinned to that branch via a VCS repo + alias (dev-fix/adapter-owned-connection-recovery as 5.9.3). Re-pin to the release tag before merge once #896 is merged and tagged.

Why

The Swoole PDOProxy keeps its own inTransaction counter (incremented on beginTransaction, decremented only on a successful commit/rollback, never reset on reconnect() or pool checkin). A connection lost mid-transaction leaks the counter and poisons the pooled connection — every later startTransaction trusts the stale counter, does a rollBack the real connection no longer holds, and fails with There is no active transaction until the process restarts.

utopia-php/database#896 moves connection-loss recovery into the adapter (Utopia\Database\PDOStatement reconnect-on-execute, with the pre-existing PDO::__call covering connection-level calls) and uses the real \PDO as the single source of truth, so the proxy is no longer needed and the desync is structurally impossible.

What changed

  • app/init/registers.php: wrap MySQL/MariaDB/Postgres connections in Utopia\Database\PDO directly instead of Swoole\Database\PDOProxy.
  • Set PDO::ATTR_ERRMODE => ERRMODE_EXCEPTION explicitly (previously the proxy forced it; Fix usage stats disabled home view #896 also defaults it).
  • composer.json: added the utopia-php/database VCS repo and repointed the require at the Fix usage stats disabled home view #896 branch (aliased as 5.9.3). composer.lock diff is a single entry: utopia-php/database 5.9.2 → #896.

Validation

php -l + pint --test clean; composer update --no-install resolves to a one-package lock change. Full e2e runs in CI. Mongo/Redis paths untouched.

Related

Cloud counterpart (cloud overrides this registers.php at runtime, plus its own Factory.php): appwrite-labs/cloud#4399.

@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing 1.9.x (before) to fix/drop-pdoproxy (after).

Before

Scenario P50 (ms) P95 (ms) Requests RPS
API total 15.48 118.97 185 33.38
Account 31.09 212.69 35 6.98
TablesDB 14.39 23.96 35 8.33
Storage 12.57 53.92 75 17.41
Functions 24.4 35.32 40 9.41

After

Scenario P50 (ms) P95 (ms) Requests RPS
API total 15.3 123.94 185 33.21
Account 32.15 199.51 35 6.9
TablesDB 14.83 20.44 35 8.21
Storage 12.75 53.54 75 17.24
Functions 24.4 38.66 40 9.32

Delta

Scenario P95 delta (ms)
API total +4.97
Account -13.19
TablesDB -3.53
Storage -0.39
Functions +3.34
Top API waits
API request Max wait (ms)
account.sessions.email.create 655.72
account.create 199.33
account.password.update 151.16

@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

🔄 PHP-Retry Summary

Flaky tests detected across commits:

Commit 7d0e7d5 - 1 flaky test
Test Retries Total Time Details
FunctionsServerTest::testCreateExecution 1 17ms Logs
Commit 541cdbe - 1 flaky test
Test Retries Total Time Details
FunctionsScheduleTest::testCreateScheduledAtExecution 1 10.59s Logs
Commit c8c6255 - 1 flaky test
Test Retries Total Time Details
TablesDBCustomClientTest::testIncrementAttribute 1 240.90s Logs
Commit 748d8ef - 1 flaky test
Test Retries Total Time Details
TablesDBCustomServerTest::testOrQueries 1 240.53s Logs
Commit 84d4b56 - 2 flaky tests
Test Retries Total Time Details
DocumentsDBCustomServerTest::testTimeout 1 132.94s Logs
LegacyTransactionsConsoleClientTest::testCommit 1 241.09s Logs

Note: Flaky test results are tracked for the last 5 commits

@abnegate
abnegate force-pushed the fix/drop-pdoproxy branch from 1d254a5 to 5fbbca6 Compare June 18, 2026 06:07
@abnegate
abnegate force-pushed the fix/drop-pdoproxy branch 4 times, most recently from 868dce9 to 9ebd445 Compare June 18, 2026 11:31
@abnegate
abnegate marked this pull request as ready for review June 18, 2026 11:35
Copilot AI review requested due to automatic review settings June 18, 2026 11:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the Swoole PDOProxy wrapper for MySQL/MariaDB and PostgreSQL connections and replaces it with a direct Utopia\Database\PDO instantiation, relying on connection-loss recovery built into the adapter layer in utopia-php/database 6.0. PDO::ERRMODE_EXCEPTION is now set explicitly since the proxy previously enforced it.

  • app/init/registers.php: PDOProxy factory closures collapsed to direct Utopia\Database\PDO construction; ERRMODE_EXCEPTION added to both driver option arrays.
  • composer.json / composer.lock: utopia-php/database advances from 5.9.2 → 6.0.0; appwrite/appwrite, utopia-php/abuse, audit, and migration are also bumped in the lockfile, a broader sweep than the PR title implies.
  • tests/unit/Utopia/ResponseTest.php: New test verifies that a Project document without oAuth2Server* fields produces no such keys in the response output and that GeneratedProject::from() returns null for those properties.

Confidence Score: 4/5

The PDO refactor in registers.php is correct and the connection-recovery logic moves cleanly into the adapter. The lockfile carries a broader package sweep than the PR title describes, including appwrite/appwrite jumping two major versions and utopia-php/audit 2.5.0 which requires PHP >=8.4 while the project root permits PHP >=8.3.

The core registers.php change is clean: Utopia\Database\PDO was already imported, ERRMODE_EXCEPTION is correctly added, and Mongo/Redis paths are untouched. The concern is on the dependency side — utopia-php/audit 2.5.0 declares php: >=8.4 in the lockfile while this branch's platform constraint remains >=8.3, which can cause runtime failures on PHP 8.3 deployments. The lockfile also resolves appwrite/appwrite from 24.2.0 to 26.1.0 and bumps abuse and migration packages, none of which are explained in the PR description or title.

composer.json and composer.lock — the resolved dependency set is significantly wider than the described change, and the PHP version floor implied by utopia-php/audit 2.5.0 is higher than the project's declared minimum.

Important Files Changed

Filename Overview
app/init/registers.php Drops PDOProxy wrapper; constructs Utopia\Database\PDO directly with explicit ERRMODE_EXCEPTION for both MySQL/MariaDB and PostgreSQL paths. The import was already present; removal of PDOProxy is clean.
composer.json Bumps utopia-php/database 5→6.0., but also advances abuse, audit, and migration beyond the one-package change the PR title describes. utopia-php/audit 2.5. requires PHP >=8.4 while the project root still permits PHP >=8.3.
composer.lock Lock resolves appwrite/appwrite from 24.2.0 to 26.1.0 and bumps utopia-php/abuse, audit, migration alongside the database package — broader sweep than described in the PR.
tests/unit/Utopia/ResponseTest.php Adds a test verifying that a Project document without oAuth2Server fields produces no such keys in the response output and that GeneratedProject::from() returns null for those properties. Logically sound addition.

Reviews (12): Last reviewed commit: "fix: address pdoproxy review comments" | Re-trigger Greptile

Comment thread composer.json Resolved
Comment thread .github/workflows/nightly.yml Resolved
Comment thread composer.json Resolved
@abnegate
abnegate force-pushed the fix/drop-pdoproxy branch from 428d83f to a9a079f Compare June 18, 2026 12:25
Comment thread .github/workflows/nightly.yml Resolved
@abnegate
abnegate force-pushed the fix/drop-pdoproxy branch 6 times, most recently from c8c6255 to 748d8ef Compare June 19, 2026 08:52
@abnegate
abnegate force-pushed the fix/drop-pdoproxy branch from 748d8ef to 84d4b56 Compare June 19, 2026 09:31
@abnegate
abnegate merged commit fde5d02 into 1.9.x Jun 19, 2026
349 of 350 checks passed
@abnegate
abnegate deleted the fix/drop-pdoproxy branch June 19, 2026 10:11
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.

2 participants