php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57407 SSH does not disconnect gracefully
Submitted: 2006-11-29 10:04 UTC Modified: 2009-02-08 10:28 UTC
From: peter dot wilton-jones at eads dot com Assigned: mikesul (profile)
Status: Closed Package: ssh2 (PECL)
PHP Version: 5.2.0 RC4 OS: Windows 2003
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: peter dot wilton-jones at eads dot com
New email:
PHP Version: OS:

 

 [2006-11-29 10:04 UTC] peter dot wilton-jones at eads dot com
Description:
------------
PHP 5.2.0 final release

I have a page that refreshes every minute. In that page, I open an ssh
session and obtain data. There is no way to close the ssh connection. On
reload, php opens a new connection but does not terminate the last one
or reuse the existing one.
Running a NETSTAT command reveals numerous connections in the CLOSE_WAIT
status after several minutes.
Can a close SSH option be included?


Reproduce code:
---------------
<?php
$connection = ssh2_connect('myserver',22);
ssh2_auth_password($connection,'username','password');
$stream = ss2_exec($connection,'df -k',FALSE);
stream_set_blocking($stream, TRUE);
$output = fread($stream,4096);
fclose($stream);
echo $output;
?>


Expected result:
----------------
Connection should show nothing


Actual result:
--------------
netstat -a shows

----------------
TCP     myweb:xxxx      myserver:22         CLOSE_WAIT
TCP     myweb:xxxx      myserver:22         CLOSE_WAIT
TCP     myweb:xxxx      myserver:22         CLOSE_WAIT
TCP     myweb:xxxx      myserver:22         CLOSE_WAIT
TCP     myweb:xxxx      myserver:22         CLOSE_WAIT
TCP     myweb:xxxx      myserver:22         CLOSE_WAIT
TCP     myweb:xxxx      myserver:22         CLOSE_WAIT
TCP     myweb:xxxx      myserver:22         CLOSE_WAIT
TCP     myweb:xxxx      myserver:22         CLOSE_WAIT
TCP     myweb:xxxx      myserver:22         CLOSE_WAIT
---------------


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-11 23:51 UTC] jbrady at sbccd dot cc dot ca dot us
I found this to be a problem in ssh2.c. When it closes the connection, it always uses close, even though closesocket should be used on windows.

I made the following changes and it works for me, no more close_waits just time_waits.

Line 361:
-------------------------------
		close(socket);
-------------------------------
#ifdef WIN32
		closesocket(socket);
#else
		close(socket);
#endif
-------------------------------

Line 441:
-------------------------------
		close(socket);
-------------------------------
#ifdef WIN32
		closesocket(socket);
#else
		close(socket);
#endif
-------------------------------

Line 1159:
-------------------------------
		close((*data)->socket);
-------------------------------
#ifdef WIN32
		closesocket((*data)->socket);
#else
		close((*data)->socket);
#endif
-------------------------------
 [2008-07-15 18:28 UTC] news dot francoisxavier at free dot fr
This bug is always present in the last release (tested with PHP v5.2.5 + php_ssh2.dll v5.2.1.1 on Windows XP SP2).

Is it that someone could fix this bug definitively in the source code please ?
 [2009-01-08 04:40 UTC] steven at salvania dot be
This fix worked for me too! (WindowsXP + PHP 5.2.8)

Before it crashed upon disconnecting, now it gracefully closes the connection.
 [2009-02-08 10:28 UTC] mikesul@php.net
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.

I finally got a Windows build of this up and running. In debug mode, the old behavior did actually throw a warning.
 [2010-04-07 03:13 UTC] silvia dot cernuda at gmail dot com
Hi mikesul,
I have the same problem whith 5.2.13 php version. In which 
version is solved?
Thanks
 [2015-01-05 14:45 UTC] slegersjohn at gmail dot com
This bug still persists on my Linux Mint PHP 5.4 installation.

Closing a SSH connection manually fails every time. When several SSH connections are opened at the same time, port 22 is blocked and no new SSH connections are possible.

The issue also occurs when using pure PHP implementations of SSH, like http://phpseclib.sourceforge.net/.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC