[php-src] Issue #8409: SSL handshake timeout leaves persistent connections hanging

From: Date: Wed, 20 Apr 2022 16:43:42 +0000
Subject: [php-src] Issue #8409: SSL handshake timeout leaves persistent connections hanging
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241102@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8409 Author: 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 <?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

« previous php.bugs (#241102) next »