ParallelSSH / ssh2-python

Python bindings for libssh2 C library.
https://parallel-ssh.org
GNU Lesser General Public License v2.1
228 stars 70 forks source link

Exception occurred ('Error code %s not known', -1073740940) when multiple connections #170

Closed dougpuob closed 2 years ago

dougpuob commented 2 years ago

Directions

I use ssh2-python in a server-client python project. The server will launch one or more QEMU whose guest OS is Windows 10, then the server will create an SSH connection to Windows 10 and execute my program (C++ with Google Test).

One by one is pretty fine, but the situation with one to multiple the python program will catch an exception ('Error code %s not known', -1073740940). The hex value of -1073740940 is 0xC0000374, which seems a STATUS_HEAP_CORRUPTION error from Win32.

The tricky problem is the exception occurred when only multiple connections. At the same time, sometimes it prints expect the result, sometimes prints nothing.

Bug reports

Code to reproduce

try:
    ssh_chanl = self.conn_ssh_session.open_session()
    new_cmdstr = cmdstr
    if self.workdir_path:
        if self.os_kind == config_next.os_kind().windows:
            new_cmdstr = "cd {} & {}".format(self.workdir_path, cmdstr)
        else:
            new_cmdstr = "cd {} ; {}".format(self.workdir_path, cmdstr)
    ssh_chanl.execute(new_cmdstr)

    size, data = ssh_chanl.read()
    ...
    size, data = ssh_chanl.read_stderr()
    ...

    ssh_chanl.close()
    ssh_chanl.wait_eof()
    ssh_chanl.get_exit_status()  <-- *** Exception occurred HERE !!! ***

Traceback

'Error code %s not known', -1073740940

> 0xC0000374
> STATUS_HEAP_CORRUPTION

Expected behaviour: [What was expected to happen.]

Call get_exit_status() function and never raise exceptions.

Actual behaviour: [What actually happened.]

Catch an exception with the get_exit_status() function when multiple connection.

Additional info: [Include version of libssh2 and any other relevant information.]

None.

pkittenis commented 2 years ago

Hi there,

Thanks for the interest and report.

Can you show complete and reproducible code to reproduce the issue. The code above is not complete, and does not show or clarify what is meant by 'multiple connections'.

dougpuob commented 2 years ago

Hi there,

Thanks for the interest and report.

Can you show complete and reproducible code to reproduce the issue. The code above is not complete, and does not show or clarify what is meant by 'multiple connections'.

Hi @pkittenis , Thank you for your reply.

The complete code please reference to the link (https://github.com/dougpuob/qemu-tasker/blob/be37e08190d6df9a2a8f6bd3634ef095997e2603/src/module/sshclient.py#L185)

About 'multiple connections'. I use ssh2-python in Continuous integration (CI) environment. The Linux Machine will launch the corresponding number of QEMU processes, then the CI runners connect to those guest OSes with ssh2-python library.

Before calling the get_exit_status() function, I upload files by sftp, then execute a C++ unit test program.

                      +-------------------------------------+    
                      |           Linux Machine             |
                      +-------------------------------------+    
CI Runner(A) --ssh--> | PortFw 10010:22 (A)QEMU(Windows 10) |
CI Runner(B) --ssh--> | PortFw 10020:22 (B)QEMU(Windows 10) | 
CI Runner(C) --ssh--> | PortFw 10030:22 (C)QEMU(Windows 10) |
CI Runner(D) --ssh--> | PortFw 10040:22 (D)QEMU(Windows 10) |
CI Runner(E) --ssh--> | PortFw 10050:22 (E)QEMU(Windows 10) |
CI Runner(F) --ssh--> | PortFw 10060:22 (F)QEMU(Windows 10) |
                      +-------------------------------------+  

- CI Runner: Those runners are executing in Windows Container in a Windows machine.
- PortFw: The port forward is done by QEMU

Above actions are executed in the "Test" stage. image

pkittenis commented 2 years ago

Use parallel-ssh for high level clients based on this library.

I don't see anything that points to an issue with ssh2-python. Closing. If you can show some complete and stand alone code that reproduces an issue can re-open. The above code works fine for me.