fix: recover failed pool connections#33
Conversation
|
Thanks for contributing! This repository is a read-only mirror — development for this library happens in |
Greptile Summary
Confidence Score: 5/5The lifecycle changes are well-scoped and covered by targeted regression tests across single-resource and grouped borrows. No code issues were identified in the reviewed changes, and the implementation includes coverage for recovery success, failed recovery, replacement behavior, native resources, exception preservation, grouped cleanup, and telemetry recording.
What T-Rex did
Reviews (6): Last reviewed commit: "fix: release all grouped resources" | 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
|
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.