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

Prevent Paramiko deadlock when test sends more than 2MB to stdout #779

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,12 @@ def test_get_hosts():
("a", 10),
("a", 1),
]


@pytest.mark.testinfra_hosts(*HOSTS)
def test_command_deadlock(host):
# Test for deadlock when exceeding Paramiko transport buffer (2MB)
# https://docs.paramiko.org/en/latest/api/channel.html#paramiko.channel.Channel.recv_exit_status
size = 3 * 1024 * 1024
output = host.check_output(f"python3 -c 'print(\"a\" * {size})'")
assert len(output) == size
2 changes: 1 addition & 1 deletion testinfra/backend/paramiko.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ def _exec_command(self, command: bytes) -> tuple[int, bytes, bytes]:
if self.get_pty:
chan.get_pty()
chan.exec_command(command)
rc = chan.recv_exit_status()
stdout = b"".join(chan.makefile("rb"))
stderr = b"".join(chan.makefile_stderr("rb"))
rc = chan.recv_exit_status()
return rc, stdout, stderr

def run(self, command: str, *args: str, **kwargs: Any) -> base.CommandResult:
Expand Down
Loading