#45808 [Opn->Fbk]: stream_socket_enable_crypto() blocks and eats CPU

From: Date: Mon, 15 Sep 2008 07:22:45 +0000
Subject: #45808 [Opn->Fbk]: stream_socket_enable_crypto() blocks and eats CPU
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-128975@lists.php.net to get a copy of this message
 ID:               45808
 Updated by:       jani@php.net
 Reported By:      six at aegis-corp dot org
-Status:           Open
+Status:           Feedback
 Bug Type:         Streams related
 Operating System: Linux 2.6
 PHP Version:      5.3.0alpha1
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.3-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.3-win32-installer-latest.msi




Previous Comments:
------------------------------------------------------------------------

[2008-08-13 17:41:01] six at aegis-corp dot org

Description:
------------
The documentation says about stream_socket_enable_crypto :

Returns TRUE on success, FALSE if negotiation has failed or 0 if there
isn't enough data and you should try again (only for non-blocking
sockets). 

In practice, if you feed a non blocking server socket to it, it will
block and consume lots of CPU until the SSL/TLS handshake is done or the
client connection is dropped.

Reproduce code:
---------------
<?php

$s = stream_socket_server("tcp://127.0.0.1:8888");
$c = stream_socket_accept($s);
stream_set_blocking($c, false);

$ret = stream_socket_enable_crypto($c, true,
STREAM_CRYPTO_METHOD_TLS_SERVER);

var_dump($ret);

?>

then just "telnet localhost 8888" from another term

Expected result:
----------------
script should print "int(0)" and exit

Actual result:
--------------
script blocks at the stream_socket_enable_crypto() call and is stuck in
a CPU consuming loop until the client connection is either handshaked or
dropped.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45808&edit=1



Thread (13 messages)

« previous php.bugs (#128975) next »