Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow request_exec with async I/O and more #576

Merged
merged 8 commits into from
Feb 6, 2024
Merged

Conversation

pbrezina
Copy link
Contributor

@pbrezina pbrezina commented Feb 2, 2024

This PR add calls to libssh request_exec() and relevant functions in order
to allow non-blocking async I/O. I need this to replace parallel-ssh which
unfortunately became a dead project, incompatible with Python 3.12+.

Additionally, it adds call to libssh request_send_signal() which allows to
send signals to the remote process if SSH server supports it.

I also fixed few bugs that I stumbled upon.

SUMMARY

$sbj.

ISSUE TYPE
  • Bugfix Pull Request
  • Docs Pull Request
  • Feature Pull Request
ADDITIONAL INFORMATION

N/A

@pbrezina pbrezina force-pushed the extras branch 3 times, most recently from e166d74 to 92572c3 Compare February 2, 2024 15:53
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Feb 2, 2024
tests/unit/channel_test.py Outdated Show resolved Hide resolved
tests/unit/channel_test.py Outdated Show resolved Hide resolved
tests/unit/channel_test.py Outdated Show resolved Hide resolved
tests/unit/channel_test.py Outdated Show resolved Hide resolved
tests/unit/channel_test.py Outdated Show resolved Hide resolved
@pbrezina pbrezina force-pushed the extras branch 5 times, most recently from de1d4eb to 87fc2bd Compare February 5, 2024 12:16
@pbrezina
Copy link
Contributor Author

pbrezina commented Feb 5, 2024

It is ready for next round of review. I addresses all comments, leaving few as "unresolved" in case you want to discuss it further.

@pbrezina pbrezina force-pushed the extras branch 2 times, most recently from 6561702 to 822f443 Compare February 6, 2024 10:11
To allow asynchronous handling of the execution.
OpenSSH now supports receiving signals for a long time. This is
useful when you need to communicate with a process via signals.
If recv_nonblocking is called and the ssh command ended with EOF
and empty output, the following error is produced because nbytes ==
SSS_EOF == -127:

```
File "src/pylibsshext/channel.pyx", line 112, in pylibsshext.channel.Channel.read_nonblocking
SystemError: Negative size passed to PyBytes_FromStringAndSize
```

It is better to handle it gracefully.
When doing asynchronous I/O it is usefull to know when EOF is hit
after polling for data.
It may happen that a garbage collector collects Session object befor
unclosed Channel. Then Channel's destructor tries to close the channel,
libssh session is accessed but it is already freed, thus causing
segfault.

Keeping reference to the Session object makes sure that Session
is collected after Channel.
@pbrezina
Copy link
Contributor Author

pbrezina commented Feb 6, 2024

Thank you. It is ready for next round.

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the well-explained patch!

Previous implementation of wait_for_svc_ready_state was not robust
enough as it could return even if further ssh connections kept failing.
@webknjaz webknjaz merged commit 80f74e5 into ansible:devel Feb 6, 2024
144 of 163 checks passed
webknjaz pushed a commit that referenced this pull request May 31, 2024
As of #576, `ssh` client started being used in tests to ensure that
sshd is ready to receive connectoins. That PR failed to include this
patch so it's being applied separately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants