[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help, channel_read() blocks forever before EOF


Hello,

Your loop is not checking for SSH_ERROR. Perhaps you should change it to if(... && channel_poll(channel, 0) > 0).

Your stacktrace shows that you are reading on a socket that has no data. Why don't you try channel_read_nonblocking() instead?

    -- Paulo

On 16/05/11 10:39, Zhang Qian wrote:
Hi,

I wrote a program in a RHEL linux machine which tries to execute a powershell script remotely on a Windows 2008 server, and get the result back. In the Windows 2008 server, I have WinSSHD installed and running.

I found my program will always hang at channel_read(), see the following callstack:
(gdb) bt
#0  0x000000381f4d4755 in recv () from /lib64/libc.so.6
#1 0x00002aaaaaaca2cc in ssh_socket_unbuffered_read (s=0x605720, buffer=0x60b430, len=16) at socket.c:135 #2 0x00002aaaaaaca338 in ssh_socket_completeread (s=0x605720, buffer=0x60b430, len=16) at socket.c:197 #3 0x00002aaaaaacaa63 in ssh_socket_wait_for_data (s=0x605720, session=0x605050, len=<value optimized out>) at socket.c:297
#4  0x00002aaaaaac3ea9 in packet_read2 (session=0x605050) at packet.c:66
#5 0x00002aaaaaab92e0 in channel_read (channel=0x60b9b0, buffer=0x60ac60, bytes=498, is_stderr=<value optimized out>)
    at channels.c:850
#6 0x0000000000401e74 in helper_SSHChannelGets (sessionRec=0x605010, maxBytesToRead=498, result=0x7fffffffe478, timeout_in_sec=0)
    at sshutils.c:323
#7 0x0000000000402827 in helper_SSHGets (sessionRec=0x605010, resultSize=513, result=0x7fffffffe530 " <Property Name=\"VMName\">Test_VM</Property>\r\n", timeout_in_sec=0) at sshutils.c:686
#8  0x0000000000402bfa in SSHGets (sessionRec=0x605010, resultSize=513,
result=0x7fffffffe530 " <Property Name=\"VMName\">Test_VM</Property>\r\n") at sshutils.c:826
#9  0x0000000000401499 in main () at main.c:25

I am sure the EOF did not happen, so why did channel_read() block there and never return? Only about 1/3 result can be returned back.

In my program, I call channel_request_exec() to execute the powershell script remotely, and then call channel_read() in a while loop to get the stdout of that script:
    ...
    /* The following code are in a while loop */
    if (channel_is_open(channel) &&  channel_poll(channel,0)) {
        curr_bytes=channel_read(channel,readbuf, bytes_to_read, 0);
        ...

Is there any mistakes in my program? Or any configurations I should do in WinSSHD? Or try another SSH daemon for Windows?

Any help will be really appreciated, thanks!



Regards,
Qian


References:
Need help, channel_read() blocks forever before EOFZhang Qian <zhq527725@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org