When closing a connection on a server using TLS, eg:
<?phprequire__DIR__ . '/vendor/autoload.php';
$server = newReact\Socket\TcpServer($port = 9900);
$server = newReact\Socket\SecureServer($server, null, [
'local_cert' => 'server.pem',
'passphrase' => 'secret'
]);
$server->on('connection', function (React\Socket\ConnectionInterface$connection) {
echo'[' . $connection->getRemoteAddress() . ' connected]' . PHP_EOL;
// do stuff$connection->end();
});the connection is not closed properly, as
| publicfunctionhandleClose() |
| { |
| if (!\is_resource($this->stream)) { |
| return; |
| } |
| |
| // Try to cleanly shut down socket and ignore any errors in case other |
| // side already closed. Underlying Stream implementation will take care |
| // of closing stream resource, so we otherwise keep this open here. |
| @\stream_socket_shutdown($this->stream, \STREAM_SHUT_RDWR); |
| } |
uses
https://www.php.net/manual/en/function.stream-socket-shutdown.php.
Note comment https://www.php.net/manual/en/function.stream-socket-shutdown.php#125659 which states tls does not get shut down properly that way.
Solution seems to be to replace @\stream_socket_shutdown($this->stream, \STREAM_SHUT_RDWR); with \fclose($this->stream).
Other solution seems to be to call @\stream_socket_enable_crypto($this->stream, false); before the socket shutdown as mentioned in comment https://www.php.net/manual/en/function.stream-socket-shutdown.php#126303
When closing a connection on a server using TLS, eg:
the connection is not closed properly, as
socket/src/Connection.php
Lines 123 to 133 in e04478a
uses https://www.php.net/manual/en/function.stream-socket-shutdown.php.
Note comment https://www.php.net/manual/en/function.stream-socket-shutdown.php#125659 which states tls does not get shut down properly that way.
Solution seems to be to replace
@\stream_socket_shutdown($this->stream, \STREAM_SHUT_RDWR);with\fclose($this->stream).Other solution seems to be to call
@\stream_socket_enable_crypto($this->stream, false);before the socket shutdown as mentioned in comment https://www.php.net/manual/en/function.stream-socket-shutdown.php#126303