Bug #77308 [Com]: Unbuffered queries memory leak

From: Date: Mon, 18 Mar 2019 12:38:12 +0000
Subject: Bug #77308 [Com]: Unbuffered queries memory leak
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220041@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77308&edit=1

 ID:                 77308
 Comment by:         alex at alex-at dot net
 Reported by:        sjon at hortensius dot net
 Summary:            Unbuffered queries memory leak
 Status:             Closed
 Type:               Bug
 Package:            MySQL related
 Operating System:   archlinux
 PHP Version:        7.3.0
 Assigned To:        dmitry
 Block user comment: N
 Private report:     N

 New Comment:

Still present in 7.3.3

Some details of test run:

---

1. Versions

#/opt/php71/bin/php -v
PHP 7.1.27 (cli) (built: Mar 18 2019 13:00:22) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

# /opt/php72/bin/php -v
PHP 7.2.16 (cli) (built: Mar 18 2019 13:03:57) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

# /opt/php73/bin/php -v
PHP 7.3.3 (cli) (built: Mar 18 2019 13:07:58) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies

---

2. Top data for ~10 sec of script run

7.1: 112241 root      20   0  307892  13932   8396 R 100.0  0.2   0:11.82 /opt/php71/bin/php
./test.php

7.2: 111796 root      20   0  310480  14228   8460 R  99.7  0.2   0:10.41 /opt/php72/bin/php
./test.php

7.3: 110517 root      20   0 1148804 848480   8716 R  99.7 10.4   0:10.37 /opt/php73/bin/php
./test.php

You can easily see RES size growing from stable 14M on PHP 7.1/7.2 to 840M+ on PHP 7.3. The script
fails with out of memory error eventually (Allowed memory size of 1073741824 bytes exhausted (tried
to allocate 16384 bytes) in /config/scripts/test.php on line 10)

---

3. Script excerpt (it's ultimately simple, but the query returns 11+ million rows)

#!/opt/php73/bin/php
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('memory_limit', '1G');

$db = new MySQLi('<server>', '<login>',
'<password>', 'radius');
$res = $db->query('SELECT AcctSessionId AS sid,
AcctUniqueId AS uid FROM radacct ORDER BY
AcctSessionId, AcctUniqueId', MYSQLI_USE_RESULT);
while (is_array($row = $res->fetch_assoc()));
$res->free();

---


Previous Comments:
------------------------------------------------------------------------
[2019-03-18 11:57:36] alex at alex-at dot net

No, not running PDO, just new MySQLi class instantiation. Will check 7.3.3 and report though.

------------------------------------------------------------------------
[2019-03-06 09:34:36] nikic@php.net

@alex: If you are disabling emulated prepared statements, then you're likely hitting bug
#77599, which is fixed in 7.3.3.

------------------------------------------------------------------------
[2019-03-06 09:28:22] alex at alex-at dot net

Still experiencing unbuffered query memory leak on 7.3.2. The test case is simple: obtaining 11
million rows with just fetch_assoc in a loop, no other code.

------------------------------------------------------------------------
[2019-02-01 09:05:18] nikic@php.net

Related To: Bug #77554

------------------------------------------------------------------------
[2019-01-14 11:00:06] dmitry@php.net

Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1a306cc9a1679a758c859731a78429429830a439
Log: Fixed bug #77308 (Unbuffered queries memory leak)

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=77308


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


Thread (13 messages)

« previous php.bugs (#220041) next »