php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75283 Disconnection not detected by socket_read()
Submitted: 2017-09-29 09:54 UTC Modified: 2021-06-13 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: privacy dot and dot spam dot protection at gmx dot fr Assigned: cmb (profile)
Status: No Feedback Package: Sockets related
PHP Version: 7.0.24 OS: Debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: privacy dot and dot spam dot protection at gmx dot fr
New email:
PHP Version: OS:

 

 [2017-09-29 09:54 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-29 11:13 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2017-09-29 11:13 UTC] 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 13:18 UTC] privacy dot and dot spam dot protection at gmx dot fr
-Status: Feedback +Status: Open
 [2017-09-29 13:18 UTC] 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
 [2021-06-02 11:00 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-06-02 11:00 UTC] cmb@php.net
Is this still an issue with any of the actively supported PHP
versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-06-13 04:22 UTC] php-bugs at lists dot php dot net
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 "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 10:01:28 2024 UTC