Skip to content

SSL handshake timeout leaves persistent connections hanging #8409

Closed
@jlesueur

Description

@jlesueur

Description

We have a redis server, we're using the phpredis extension to connect to it. The phpredis extension is built on top of php's stream sockets. The bug I'm reporting can be duplicated without the phpredis extension.

Sometimes, a redis server will timeout during the ssl negotiation. This will generate a warning from php_openssl_enable_crypto(). If there is an error handler that stops execution on warnings, then the underlying connection will be left in place, even without SSL negotiation succeeding. We can see this by looking at client list on the redis server. The connection will still be hanging around, for as long as the fpm process exists.

For testing purposes, we can disable tls on the redis server, which will force the "handshake timed out" results.

Is there a reason that the connection is maintained even if the ssl negotiation fails? Could/should php close the connection when ssl negotiation fails?

The following code:

<?php

set_error_handler(function($errno, $errstring, $errfile, $errline, $errcontext) {
	var_dump(get_resources());
	exit(1);
});
$socket = stream_socket_client("tls://redis:6379", $error_code, $error_message, 0.2, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, stream_context_create(['tls' => ['verify_peer_name' => false]]));
echo "here";

Resulted in this output:

array(2) { [2]=> resource(2) of type (stream-context) [3]=> resource(3) of type (persistent stream) }

But I expected this output instead:

array(2) { [2]=> resource(2) of type (stream-context) }

PHP Version

PHP 7.4.28

Operating System

Ubuntu 20.04

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions