feat: add flushAll() method to Pool and PoolFactory#7698
Merged
limingxinleo merged 4 commits intohyperf:masterfrom Jan 25, 2026
Merged
feat: add flushAll() method to Pool and PoolFactory#7698limingxinleo merged 4 commits intohyperf:masterfrom
flushAll() method to Pool and PoolFactory#7698limingxinleo merged 4 commits intohyperf:masterfrom
Conversation
Add Pool::flushAll() to close all connections in the channel. Add PoolFactory::flushAll() to redis and db-connection packages to close all connections across all managed pools. This is useful for: - Test suites: prevent file descriptor exhaustion when running many tests that each create fresh application containers - Graceful shutdown: explicitly release all connections - Resource cleanup in long-running processes
limingxinleo
previously approved these changes
Jan 25, 2026
limingxinleo
approved these changes
Jan 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a
flushAll()method to:Hyperf\Pool\Pool- closes all connections in the poolHyperf\Redis\Pool\PoolFactory- closes all connections in all Redis poolsHyperf\DbConnection\Pool\PoolFactory- closes all connections in all database poolsWhy is this needed?
Problem: File descriptor exhaustion in test suites
When running large PHPUnit test suites with
RunTestsInCoroutine(2000+ tests), each test creates a new application container with new pool instances. The old pools are not explicitly closed - they wait for garbage collection.PHP's garbage collector does not run immediately. This causes file descriptors (socket connections) to accumulate until the process hits the OS limit (
ulimit -n), resulting in errors like:This is a known PHPUnit issue (sebastianbergmann/phpunit#182) where file handles accumulate across tests. With coroutines, the problem is more severe because connection pools hold multiple socket file descriptors.
Solution
With
flushAll(), test frameworks can explicitly close all pool connections between tests:Other use cases
Implementation
Pool::flushAll()reuses the existingflushOne(true)method:PoolFactory::flushAll()callsflushAll()on all managed pools:Note
The
RedisPoolStubtest class had its ownflushAll()implementation. This PR removes it since the basePoolclass now provides this method.Tests
testPoolFlushAlltoPoolTest.phpPoolFactoryTest.phpfor Redis packagePoolFactoryTest.phpfor db-connection packageAll tests pass with
co-phpunit.