Bug #69428 [Dup]: fgets blocks and consumes CPU on a non-blocking TLS stream without data
Edit report at https://bugs.php.net/bug.php?id=69428&edit=1
ID: 69428
Updated by: rdlowrey@php.net
Reported by: nathan dot renniewaldock at gmail dot com
Summary: fgets blocks and consumes CPU on a non-blocking TLS
stream without data
Status: Duplicate
Type: Bug
Package: OpenSSL related
Operating System: Ubuntu 12.04
PHP Version: 5.6.7
Block user comment: N
Private report: N
New Comment:
This is now fixed upstream in 5.5 and 5.6 branches. The RC period has already begun for 5.5.24 and
5.6.8 so this fix will not be reflected in releases until 5.5.25 and 5.6.9.
In the meantime you can try with the latest snap builds (after a few hours pass):
http://snaps.php.net/
http://windows.php.net/snapshots/
Previous Comments:
------------------------------------------------------------------------
[2015-04-13 20:01:46] schmidt dot a at rogers dot com
I've experienced the same thing on 5.5.23 (this did not occur in 5.5.22). There were 4 issues
fixed in 5.5.23 related to streams and openssl.
------------------------------------------------------------------------
[2015-04-11 23:32:50] nathan dot renniewaldock at gmail dot com
Must've missed that one when searching. But that one is correct, my blank lines are from it
returning after timeout is exceeded.
------------------------------------------------------------------------
[2015-04-11 23:03:36] requinix@php.net
Related To: Bug #69402
------------------------------------------------------------------------
[2015-04-11 23:02:25] requinix@php.net
Duplicate of bug #69402
------------------------------------------------------------------------
[2015-04-11 22:56:27] nathan dot renniewaldock at gmail dot com
Description:
------------
TLS streams are blocking and consuming 100% CPU when there's no data when set to non-blocking.
Test script is using a local IRC server so I didn't have to write a server. Removing tls:// and
changing the port to 6667 works as expected.
Test script:
---------------
<?php
$context = stream_context_create();
stream_context_set_option($context, "ssl", "verify_peer", false);
$fp = stream_socket_client("tls://localhost:6697", $errno, $errstr, 10,
STREAM_CLIENT_CONNECT, $context) or die();
stream_set_blocking($fp, 0);
while (!feof($fp)) {
echo microtime(true)." Reading...\n";
$line = fgets($fp);
echo microtime(true)." $line\n";
if (!$fp) {
usleep(10000);
}
}
@fclose($fp);
?>
Expected result:
----------------
"Reading..." should repeat every ~10ms and CPU usage should be low
Actual result:
--------------
$ php test.php
1428791498.132599 Reading...
1428791498.171197 :localhost NOTICE AUTH :*** Looking up your hostname...
1428791498.171224 Reading...
1428791498.171237 :localhost NOTICE AUTH :*** Found your hostname (cached)
1428791498.171251 Reading...
# At this point htop shows it using 100% CPU until the server send a blank line to check the
connection hasn't broken
1428791508.17128
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69428&edit=1
Thread (5 messages)