Fix SSH2 resource ownership and stream error handling#103
Open
binaryfire wants to merge 1 commit into
Open
Conversation
Guard every native channel, listener, public-key, and SFTP child operation with the owning session lifetime. Keep cleanup on the Zend side balanced after explicit disconnects, and prevent polling or stream operations from dereferencing released libssh2 state. Make direct wrapper connection and authentication ownership transactional, release temporary SFTP resources after one-shot operations, and correct the fetched-stream refcount rollback. Preserve channel and SFTP errors as errors, reserve EOF for clean zero-byte completion, normalize EAGAIN as nonblocking backpressure, and initialize accepted-channel timeout state. Add focused PHPT coverage for ownership, descriptor release, parent loss, polling, backpressure, errors, and clean completion.
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 fixes one connected set of SSH2 resource-ownership and stream-contract bugs:
stat,unlink,rename,mkdir, andrmdirare released after each operationssh2_poll()rejects channels and listeners whose parent session is closedEAGAINis reported as zero-byte backpressure on modern PHPThese changes belong together because they share one ownership graph. Landing only part of it can leave streams that retain resources but still dereference released native state, or fix successful wrapper ownership while leaving failure paths and one-shot operations unbalanced.
No public API changes are required. Explicitly closing a session now makes its remaining child resources fail safely while their PHP-side cleanup still completes.
Testing
Added PHPT coverage for:
The extension builds cleanly against PHP 8.4 and libssh2 1.11. The complete suite was also run against a local OpenSSH fixture; its remaining failures match an unchanged
masterbuild and come from existing fixture assumptions.