php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69393 fread() function on TLS stream timeout
Submitted: 2015-04-07 10:29 UTC Modified: 2015-04-14 13:28 UTC
Votes:8
Avg. Score:4.6 ± 0.7
Reproduced:8 of 8 (100.0%)
Same Version:5 (62.5%)
Same OS:7 (87.5%)
From: contact at sshilko dot com Assigned: rdlowrey (profile)
Status: Closed Package: Streams related
PHP Version: 5.5.23 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: contact at sshilko dot com
New email:
PHP Version: OS:

 

 [2015-04-07 10:29 UTC] contact at sshilko dot com
Description:
------------
The fread() call on TLS (SSL) stream times out after 60 seconds and does not honor the stream_set_timeout() values.

5.5.23 (tested) and probably 5.6.7 affected, 5.5.22 worked fine.

Related git threads:

https://github.com/duccio/ApnsPHP/issues/84
https://github.com/php/php-src/pull/971


Test script:
---------------
https://gist.github.com/sshilko/41f04ddaaf5f73f0bb91

Expected result:
----------------
PHP 5.5.22-1+deb.sury.org~precise+1 (cli) (built: Feb 20 2015 11:25:27) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies


Sending 172 bytes over tls://gateway.sandbox.push.apple.com:2195:                                                                                                                                                    
Socket state:                                                                                                                                                                                                        
Array                                                                                                                                                                                                                
(                                                                                                                                                                                                                    
    [stream_type] => tcp_socket/ssl                                                                                                                                                                                  
    [mode] => r+                                                                                                                                                                                                     
    [unread_bytes] => 0                                                                                                                                                                                              
    [seekable] =>                                                                                                                                                                                                    
    [timed_out] =>                                                                                                                                                                                                   
    [blocked] =>                                                                                                                                                                                                     
    [eof] =>                                                                                                                                                                                                         
)                                                                                                                                                                                                                    
Timeout set: 1
Has errors:
string(0) ""

real    0m0.261s
user    0m0.040s
sys     0m0.036s


Actual result:
--------------
PHP 5.5.23-1+deb.sury.org~precise+2 (cli) (built: Mar 24 2015 11:00:01) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies

Sending 172 bytes over tls://gateway.sandbox.push.apple.com:2195:
Socket state:
Array
(
    [stream_type] => tcp_socket/ssl
    [mode] => r+
    [unread_bytes] => 0
    [seekable] => 
    [timed_out] => 
    [blocked] => 
    [eof] => 
)
Timeout set: 1
Has errors:
string(0) ""

real    1m0.305s
user    0m19.553s
sys     0m39.170s


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-07 11:17 UTC] contact at sshilko dot com
The actual time it takes for fread() is the stream_socket_client.timeout argument actually, even wehn the documentation says

To set a timeout for reading/writing data over the socket, use the stream_set_timeout(), as the timeout only applies while making connecting the socket. 

in 5.5.23 this timeout is also used for fread() call.
 [2015-04-09 11:14 UTC] pk at maybe-phil dot net
5.6.7 is also affected.
 [2015-04-14 13:28 UTC] rdlowrey@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: rdlowrey
 [2015-04-14 13:28 UTC] rdlowrey@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

For a long time (years) SSL streams didn't honor socket timeouts when reading. When this issue was finally addressed the fix broke stream_set_timeout() functionality on SSL streams.

The default socket timeout is still observed in these releases (which is the reason for the 60 second timeout observed). Though this bug has been fixed upstream, it wasn't discovered until 5.5.23 and 5.6.7 were already in the RC stage and couldn't be included in these releases. The next set of bugfix releases resolves this issue.
 [2015-04-17 15:45 UTC] shawn at digitalpoint dot com
Still broken in 5.6.8.
 [2015-04-20 06:12 UTC] contact at sshilko dot com
Fix Bug #69402: Reading empty SSL stream hangs until timeout
https://bugs.php.net/bug.php?id=69402

probably thats the fix 
https://git.php.net/?p=php-src.git;a=commit;h=81f356b4aea79cd8f86e16096c7ccfbc455bfc3c

and the comment says

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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 02:01:29 2024 UTC