Bug #69428 [NEW]: fgets blocks and consumes CPU on a non-blocking TLS stream without data
From: nathan dot renniewaldock at gmail dot com
Operating system: Ubuntu 12.04
PHP version: 5.6.7
Package: OpenSSL related
Bug Type: Bug
Bug description:fgets blocks and consumes CPU on a non-blocking TLS stream without data
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 bug report at https://bugs.php.net/bug.php?id=69428&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69428&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69428&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69428&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69428&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69428&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69428&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69428&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69428&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69428&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69428&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69428&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69428&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69428&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69428&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69428&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69428&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69428&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69428&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69428&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69428&r=mysqlcfg
Thread (5 messages)
- nathan dot renniewaldock at gmail dot com