Bug #75283 [Opn->Fbk]: Disconnection not detected by socket_read()
| From: | cmb@php.net | Date: | Wed, 02 Jun 2021 11:00:08 +0000 |
| Subject: | Bug #75283 [Opn->Fbk]: Disconnection not detected by socket_read() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234162@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75283&edit=1
ID: 75283
Updated by: cmb@php.net
Reported by: privacy dot and dot spam dot protection at gmx dot
fr
Summary: Disconnection not detected by socket_read()
-Status: Open
+Status: Feedback
Type: Bug
Package: Sockets related
Operating System: Debian
PHP Version: 7.0.24
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Is this still an issue with any of the actively supported PHP
versions[1]?
[1] <https://www.php.net/supported-versions.php>
Previous Comments:
------------------------------------------------------------------------
[2017-09-29 13:18:09] privacy dot and dot spam dot protection at gmx dot fr
I haven't got server code because I use an RS232 TCP/IP converter's box. Problem happens
when there's an ellectric shutdown, PHP socket_read function doesn't detect disconnection
------------------------------------------------------------------------
[2017-09-29 11:13:27] requinix@php.net
Looks like the socket is still open, not reset.
I haven't been able to reproduce your output in a way where the socket is reset/closed.
What's the server code? What's the actual client code that sends data to the server in
order to trigger the RST?
------------------------------------------------------------------------
[2017-09-29 09:54:56] privacy dot and dot spam dot protection at gmx dot fr
Description:
------------
According to documentation, an empty string ("") is returned by socket_read() when
there's no more data to read and false value on error (including if the remote host has closed
the connection).
However when socket_read has no data to read false is still returned.
So it's impossible to detect if connection has been reseted by pear.
Test script:
---------------
$co = false;
while (!$co) {
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket !== false) echo "OK 1.\n";
$result = socket_connect($socket, $address, $service_port);
if ($socket !== false) {
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1,
"usec" => 1));
echo "OK 2.\n";
$co = true;
}
}
while (true) {
socket_clear_error($socket);
$out = socket_read($socket, 2048);
$socket_last_error = socket_last_error($socket);
$strErr = socket_strerror($socket_last_error) . ' ' . $socket_last_error;
echo date('Ymd H:i:s') . " : $strErr ($socket_last_error) => " .
var_export($out, true) . PHP_EOL;
}
Expected result:
----------------
OK 1.
Try connection '9.3.0.23' on port '30001'...
OK 2.
// client's connected on server
// no data have been sent by server
20170929 11:09:17 : Success 0 (0) => ''
20170929 11:09:18 : Success 0 (0) => ''
20170929 11:09:19 : Success 0 (0) => ''
//server send data
20170929 11:09:19 : Success 0 (0) => 'a'
20170929 11:09:19 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
// no data have been sent by server
20170929 11:09:21 : Success 0 (0) => ''
20170929 11:09:22 : Success 0 (0) => ''
20170929 11:09:23 : Success 0 (0) => ''
// connection is reset by server
20170929 11:09:24 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:25 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:26 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:27 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:28 : Resource temporarily unavailable 11 (11) => false
Actual result:
--------------
OK 1.
Try connection '9.3.0.23' on port '30001'...
OK 2.
// client's connected on server
// no data have been sent by server
20170929 11:09:17 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:18 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:19 : Resource temporarily unavailable 11 (11) => false
//server send data
20170929 11:09:19 : Success 0 (0) => 'a'
20170929 11:09:19 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
20170929 11:09:20 : Success 0 (0) => 'a'
// no data have been sent by server
20170929 11:09:21 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:22 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:23 : Resource temporarily unavailable 11 (11) => false
// connection is reset by server
20170929 11:09:24 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:25 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:26 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:27 : Resource temporarily unavailable 11 (11) => false
20170929 11:09:28 : Resource temporarily unavailable 11 (11) => false
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75283&edit=1