Bug #75288 [Com]: stream_socket_enable_crypto() blocks during handshake

From: Date: Fri, 29 Sep 2017 19:15:10 +0000
Subject: Bug #75288 [Com]: stream_socket_enable_crypto() blocks during handshake
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211462@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75288&edit=1 ID: 75288 Comment by: james at jamesreno dot com Reported by: james at jamesreno dot com Summary: stream_socket_enable_crypto() blocks during handshake Status: Open Type: Bug Package: Streams related Operating System: Ubuntu 16.04 PHP Version: 7.0.24 Block user comment: N Private report: N New Comment: Might be related to the fix for one of the following bugs: - bug#72333: https://bugs.php.net/bug.php?id=72333 fwrite() on non-blocking SSL sockets doesn't work - bug#45808: https://bugs.php.net/bug.php?id=72333 stream_socket_enable_crypto() blocks during handshake Previous Comments: ------------------------------------------------------------------------ [2017-09-29 19:10:47] james at jamesreno dot com Description: ------------ When enabling ssl on a socket with php 7.0.24 the handshake blocks the socket. I expect the enable_crypto to immediately return "0" if the socket is in non-blocking mode and there is not enough data available to perform the handshake. Test script: --------------- <?php $ssl_stream_ctx = stream_context_create(array( 'ssl' => array( 'local_cert' => 'cert.pem', 'verify_peer' => FALSE, ), )); $listener = @stream_socket_server("tcp://127.0.0.1:1234",$errno,$errstr,STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $ssl_stream_ctx); stream_set_blocking($listener, FALSE); $peerName = FALSE; $sock = @stream_socket_accept($fd, 0.01, $peerName); stream_set_blocking($sock, FALSE); $data = stream_socket_recvfrom($sock,1,STREAM_PEEK); if ($data[0] == "\x16") { $sslInitStartTime = microtime(TRUE); $ret = stream_socket_enable_crypto($sock, TRUE, STREAM_CRYPTO_METHOD_SSLv23_SERVER); $sslInitEndTime = microtime(TRUE); $sslInitTime = $sslInitEndTime - $sslInitStartTime; if ($sslInitTime >= 0.1) { echo "ERROR SSL INIT TOOK TOO LONG." . PHP_EOL; } } Expected result: ---------------- Expect to return immediately and not hange > 0.1sec Actual result: -------------- Script hangs sometimes up to several seconds with "far away high-latency" clients. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75288&edit=1

« previous php.bugs (#211462) next »