Bug #71613 [Com]: nonblocking UDP stream_socket_recvfrom() memory leak

From: Date: Thu, 22 Jul 2021 15:42:12 +0000
Subject: Bug #71613 [Com]: nonblocking UDP stream_socket_recvfrom() memory leak
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235259@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71613&edit=1 ID: 71613 Comment by: paul dot smith at deepseaelectronics dot com Reported by: jnelson at archive dot org Summary: nonblocking UDP stream_socket_recvfrom() memory leak Status: Open Type: Bug Package: Performance problem Operating System: Ubuntu PHP Version: 5.5.32 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2016-02-16 21:45:52] 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(). ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71613&edit=1

« previous php.bugs (#235259) next »