php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71613 nonblocking UDP stream_socket_recvfrom() memory leak
Submitted: 2016-02-16 21:45 UTC Modified: -
Votes:6
Avg. Score:4.5 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:3 (60.0%)
From: jnelson at archive dot org Assigned:
Status: Open Package: Performance problem
PHP Version: 5.5.32 OS: Ubuntu
Private report: No CVE-ID: None
 [2016-02-16 21:45 UTC] jnelson at archive dot org
Description:
------------
While coding a UDP server with stream_socket_recvfrom(), I found a memory leak when (a) the stream is set to nonblocking mode, (b) the optional $address reference is passed, and (c) no data is ready.  If $address is not passed, there is no leak.

It appears the leak only occurs if there's some traffic on the socket, meaning that this won't happen simply listening on a quiet port.  I'm including two scripts, client.php and server.php, which must be run together for the server script to exhibit the leak.

Test script:
---------------
client.php: http://archive.org/~jnelson/client.php.txt
server.php: http://archive.org/~jnelson/server.php.txt

Expected result:
----------------
Expect memory usage to remain roughly the same for the duration of execution.

Actual result:
--------------
server.php's memory usage gradually increases over time, but only if $address is requested in the call to stream_socket_recvfrom().

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-22 15:42 UTC] paul dot smith at deepseaelectronics dot com
I'm having this same problem on PHP 7.4.16 and 8.0.3. Both are running as FPM on CentOS 7.

The issue seems to happen when stream_socket_recvfrom() is called multiple times between calls to stream_select().

A temporary workaround would be to only read a single packet after each select but this is inefficient as we have to go around the entire main loop again instead of looping until recvfrom returns false.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 06 03:01:29 2024 UTC