fix: recover failed pool connections#33
Conversation
|
Thanks for contributing! This repository is a read-only mirror — development for this library happens in |
Greptile SummaryThis PR overhauls the failure path for pool connections by routing
Confidence Score: 5/5Safe to merge; all seven previously-blocked concerns are resolved and the new logic is well-tested. The refactored acquire-then-release loop in The Important Files Changed
Reviews (8): Last reviewed commit: "chore(deps): bump utopia-php/telemetry 0..." | Re-trigger Greptile |
Greptile Summary
Confidence Score: 3/5The pool lifecycle change is well targeted but leaves edge cases around replacement failure handling and grouped acquisitions that should be addressed before merging. Focused tests and implementation changes cover the intended callback-failure path, but the cleanup path does not handle all throwable replacement failures and grouped pool usage can churn healthy resources when later acquisition fails.
What T-Rex did
|
|
Approach is sound — eviction belongs to the pool (only it can destroy + replace + keep capacity), and delegating the health decision to the resource via 1.
|
Follow-up (not a request to change this PR) — explicit
|
…ol-connections # Conflicts: # .github/workflows/tests.yml
Complements the destroy-on-failed-recovery cases: when a resource exposes a working reconnect(), release(failed) recovers and reclaims the SAME connection instead of destroying it (DAT-1904 pool-layer fix). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The observable-gauge tests read $gauge->callbacks[] (multi-observer), added in telemetry 0.4.1+; the lock was pinned at 0.4.0 (single ->callback), so those tests failed against it. 0.4.5 is within the existing ^0.4 constraint (lock-only). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Closing — this repo is now a read-only mirror of utopia-php/monorepo (see the mirror-redirect workflow), so merging here can't ship. The fix has been ported to the canonical location with monorepo style applied, the recover-and-reuse happy-path test added, and the telemetry lock bump (0.4.5) that the observable-gauge tests require: utopia-php/monorepo#75. Full pools suite green there (49 tests / 168 assertions). |
What changed
Pool::use()cleanup through a shared release path that distinguishes successful use from failed callbacks.reset()and/orreconnect()exists and succeeds; destroy and replace resources when recovery throws, returnsfalse, or no recovery hook exists.Group::use()to acquire connections explicitly, release them in reverse order, continue releasing every borrowed connection if one release throws, and record use-duration telemetry for grouped borrows.falserecovery hooks, missing recovery hooks, native resources, exception preservation, grouped acquisition cleanup, grouped release failure cleanup, and grouped use telemetry.suggestskey with a singlesuggestsection.opentelemetryandprotobufextensions in the test workflow so Composer can installutopia-php/telemetry.Why
A callback failure can leave a borrowed resource in poisoned state. Blindly reclaiming that resource puts the same broken connection back in rotation, which can amplify one connection-level failure into persistent errors for later borrowers.
The release path now keeps healthy acquisition-only resources, but prevents unrecoverable callback-failed object or native resources from cycling back into the pool. Grouped borrows now clean up all acquired connections even when one release path fails.
Verification
composer validate --strictpint --preset psr12 --testusing temporary Pint 1.x toolingphpstan analyse -c phpstan.neonusing temporary PHPStan 1.x toolingphpunit --configuration phpunit.xml tests/Pools/Adapter/StackTest.phpusing temporary PHPUnit 11.x toolingphpunit --configuration phpunit.xml tests/Pools/Adapter/SwooleTest.php --filter 'testUse|testGroupUseReclaims|testUseDestroys|testGroupUseRecords|testGroupUseReleases'using temporary PHPUnit 11.x toolingNote: the full local
composer testsuite still exits with signal 139 after an existing Swoole race-condition test reports OK under this machine's PHP 8.5/Swoole runtime. The new Swoole lifecycle tests pass cleanly, and the crash reproduces withtestSwooleCoroutineRaceConditionalone.