Fix pool cleanup and keepalive reconnection races - #573
Merged
Conversation
A lifetime sweep or idle trim can resume while close is suspended in another destroy callback. The closed channel still contains objects for draining, so maintenance can remove a healthy object and lose it when the channel rejects its requeue. Destroy rejected requeues through the existing cleanup path. Cover both maintenance operations with a controlled overlap, asserting that the healthy object is destroyed before close resumes and every object is cleaned up exactly once.
Concurrent reconnect cleanup can finish after the winning socket has closed. Check the false reconnect result before attempting a socket wait, and raise ConnectionException immediately instead of waiting until timeout and reporting socket exhaustion. Return the actual connected state after heartbeat activation and previous-channel wakeup, including closure during timer creation. Document the reconnect result and keepalive exception behavior, and cover concurrent cleanup and timer-creation closure without adding retries or shared state.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
This fixes two coroutine races in the pool lifecycle, reported during review of #572. One can skip an object's cleanup; the other waits for a socket that has already been closed and reports a misleading timeout.
Object pool cleanup
A lifetime sweep or idle trim can pause while destroying an expired object. If another coroutine closes the pool and pauses while destroying a different object, maintenance can resume and remove a healthy object from the closed channel. Returning that object to the channel fails, leaving its destroy callback uncalled and its managed entry behind.
A rejected requeue now destroys the object through the pool's existing cleanup path. The regression tests hold both cleanup operations at the relevant points and verify that every object is destroyed exactly once and the pool finishes empty.
Keepalive reconnection
When two connection attempts overlap, the losing attempt closes its unused socket. The winning socket can close while that cleanup is waiting. Reconnection then returns false, but
call()previously ignored the result and waited untilwait_timeoutbefore throwingSocketPopException.call()now checks the result and throwsConnectionExceptionimmediately when reconnection completes without an available socket. Reconnection also returns the actual connected state after heartbeat setup, covering closure during timer creation. Existing exceptions and cancellation continue to propagate without an additional reconnect attempt.The connection contract and keepalive documentation describe these results. Tests cover both closure paths, including callback execution, socket cleanup, and timer cleanup.
Validation
PHPStan, PHP formatting checks, and the object-pool and connection-pool package suites pass. The new regressions were also run against the original implementations and fail for the reported reasons.
Addresses the object cleanup comment and keepalive reconnect comment.