-
-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closing connection using TLS #320
Comments
What problem are you seeing exactly? May I ask you to provide a gist to reproduce this? Note that this call will be followed immediately by |
When the connection is closed by the server, the client outputs an error:
Replacing Lines 123 to 133 in e04478a
with public function handleClose()
{
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.
if ($this->encryptionEnabled) {
@\stream_socket_enable_crypto($this->stream, false);
}
@\stream_socket_shutdown($this->stream, \STREAM_SHUT_RDWR);
} resolves the issue. From what I understand, using |
What you're saying may be entirely correct, but we need to double check which "client outputs an error" under what circumstances exactly. I would love to add some tests to confirm correct behavior and avoid future regressions, as we can't randomly change this logic without having some safety nets in place. Perhaps you can help us by giving some clear instructions how we can reproduce the specific problem you're seeing locally? |
That is very sound and I would agree with that logic :)
I am tinkering around with a rudimentary implementation of ftps with implicit tls in PHP using reactphp. I ran into this problem when using filezilla as client. At some point, it issues the |
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#126303The text was updated successfully, but these errors were encountered: