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

From: Date: Fri, 29 Sep 2017 19:10:52 +0000
Subject: Bug #75288 [NEW]: stream_socket_enable_crypto() blocks during handshake
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211461@lists.php.net to get a copy of this message
From: james at jamesreno dot com Operating system: Ubuntu 16.04 PHP version: 7.0.24 Package: Streams related Bug Type: Bug Bug description:stream_socket_enable_crypto() blocks during handshake 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 bug report at https://bugs.php.net/bug.php?id=75288&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75288&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75288&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75288&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75288&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75288&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75288&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75288&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75288&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75288&r=support Expected behavior: https://bugs.php.net/fix.php?id=75288&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75288&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75288&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75288&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75288&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75288&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75288&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75288&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75288&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75288&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75288&r=mysqlcfg

« previous php.bugs (#211461) next »