|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58817 ssh2_connect does not timeout.
Submitted: 2009-08-19 01:27 UTC Modified: 2012-10-06 09:14 UTC
Avg. Score:4.9 ± 0.3
Reproduced:15 of 15 (100.0%)
Same Version:1 (6.7%)
Same OS:3 (20.0%)
From: drew at drewb dot com Assigned:
Status: No Feedback Package: ssh2 (PECL)
PHP Version: 5.2.6 OS: CentOS 5.3
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-08-19 01:27 UTC] drew at drewb dot com
Using pecl ssh2 ver 0.10

Every so often (once every 300 or more runs) my script ends in a php fatal error w/ max_execution_time reached.  The line pointed to by the logged error message indicates that ssh2_connect() is hung waiting for a reply from the remote host.  I would have expected the attempt to connect to have failed after a timeout.

I'm not certain yet if this is due to libssh2 or pecl ssh2.

I will try to follow up with more info and some testing, but it's difficult to set up.

Reproduce code:

$conn = ssh2_connect($remote_host, $port);

 * script fails to reach this point before 
 * max_execution_time.
if ( ! $conn )
  die("failed to connect to $remote_host on $port.");

Expected result:
sshs_connect returns false after tv seconds.
script dies w/ error message.

Actual result:
php fatal error (max_execution_time reached).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-21 17:40 UTC] deathazre at yahoo dot com
Please somehow monitor if the process is hung in a CLOSE_WAIT state.  I have this issue as well - it occurs unpredictably, occasionally, and does not re-occur on subsequent attempts. 

My debugging has lead to ssh2_connect() becoming inexplicably frozen, with a CLOSE_WAIT status and 1 byte of data in the RECV buffer.
 [2012-06-23 10:47 UTC]
-Status: Open +Status: Feedback
 [2012-06-23 10:47 UTC]
Cannot reproduce this. Have you seen this bug with newer versions of libssh2?
 [2012-10-06 09:14 UTC]
-Status: Feedback +Status: No Feedback
 [2012-10-06 09:14 UTC]
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.

 [2015-03-31 23:49 UTC] marie at bonnecomm dot net
Ubuntu 14.4.2_i386 and Ubuntu 14.4.2_x64
Using php_cli

PHP Version 5.5.9-1ubuntu4.7
extension version 0.12 
libssh2 version 1.4.3 
banner SSH-2.0-libssh2_1.4.3 

According to synaptic, libssh2-php is 0.12-1build1

Bug seems to occur when connectivity to the desired remote system is flakey (i.e. a wireless connection on the edge that fades in and out, perhaps disconnects then reconnects.)

Using set_time_limit( 10); does not seem to cause the desired timeout.
 [2015-04-01 01:42 UTC] marie at bonnecomm dot net
I have run into the same problem trying to use just plain SSH from the cli. Very likely, this is a problem with the SSH layer and not the PHP layer. Even so, the PHP layer should probably have a TIMEOUT parameter or something.
 [2015-07-14 17:09 UTC] edaroczy at talentwise dot com
We are experiencing this on a daily basis, but only on the attempt to connect to one of our customers' SFTP server.  The strace log is below, the call to poll never returns.  The other instances where the poll call returns look like "
13:05:15 poll([{fd=18, events=POLLIN}], 1, -1) = 1 ([{fd=18, revents=POLLIN}])"

13:05:16 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 18
13:05:16 fcntl(18, F_GETFL)             = 0x2 (flags O_RDWR)
13:05:16 fcntl(18, F_SETFL, O_RDWR|O_NONBLOCK) = 0
13:05:16 connect(18, {sa_family=AF_INET, sin_port=htons(22), sin_addr=inet_addr("")}, 16) = -1 EINPROGRESS (Operation now in progress)
13:05:16 poll([{fd=18, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 60000) = 1 ([{fd=18, revents=POLLOUT}])
13:05:16 getsockopt(18, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
13:05:16 fcntl(18, F_SETFL, O_RDWR)     = 0
13:05:16 fcntl(18, F_GETFL)             = 0x2 (flags O_RDWR)
13:05:16 fcntl(18, F_GETFL)             = 0x2 (flags O_RDWR)
13:05:16 fcntl(18, F_SETFL, O_RDWR|O_NONBLOCK) = 0
13:05:16 sendto(18, "SSH-2.0-libssh2_1.2.6 PHP\r\n", 27, MSG_NOSIGNAL, NULL, 0) = 27
13:05:16 recvfrom(18, 0x7fffdc6b645f, 1, 16384, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)
13:05:16 poll([{fd=18, events=POLLIN}], 1, -1
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Oct 06 14:03:44 2022 UTC