Bug #81104 [NEW]: Warning: "Failed to set memory limit to ... bytes" emitted after exit in debug

From: Date: Thu, 03 Jun 2021 23:38:13 +0000
Subject: Bug #81104 [NEW]: Warning: "Failed to set memory limit to ... bytes" emitted after exit in debug
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234201@lists.php.net to get a copy of this message
From: tandre Operating system: PHP version: master-Git-2021-06-03 (Git) Package: Scripting Engine problem Bug Type: Bug Bug description:Warning: "Failed to set memory limit to ... bytes" emitted after exit in debug Description: ------------ This only happens when PHP is built with --enable-debug, and it's only a notice. Possibly, it's deliberate. php -d memory_limit=5M test.php on the attached script will run the script successfully, and while php is shutting down, php will internally reset original ini settings, including memory_limit. This will trigger an error because the restored memory_limit is smaller than the amount of memory recorded as being in use at the time - this is more likely to affect programs with data structures that can't be garbage collected (gc_disable(); public function __construct() { $this->x = [$this]; }) ``` (gdb) b zend_error Breakpoint 1 at 0x613f69: file /path/to/php-src/Zend/zend.c, line 1561. (gdb) run Starting program: /path/to/php-8.1.0-debug-intersection-types-install/bin/php -d memory_limit=5M test.php [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Memory usage before shutting down: 11975904 Breakpoint 1, zend_error (type=21845, format=0x555556379140 "\001") at /path/to/php-src/Zend/zend.c:1561 1561 ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) { (gdb) bt #0 zend_error (type=21845, format=0x555556379140 "\001") at /path/to/php-src/Zend/zend.c:1561 #1 0x0000555555ac1824 in OnChangeMemoryLimit (entry=0x55555637ebe0, new_value=0x55555637ec60, mh_arg1=0x0, mh_arg2=0x0, mh_arg3=0x0, stage=8) at /path/to/php-src/main/main.c:276 #2 0x0000555555c1d8eb in zend_restore_ini_entry_cb (ini_entry=0x55555637ebe0, stage=8) at /path/to/php-src/Zend/zend_ini.c:54 #3 0x0000555555c1db8c in zend_ini_deactivate () at /path/to/php-src/Zend/zend_ini.c:129 #4 0x0000555555b672ac in zend_deactivate () at /path/to/php-src/Zend/zend.c:1290 #5 0x0000555555ac4d17 in php_request_shutdown (dummy=0x0) at /path/to/php-src/main/main.c:1823 #6 0x0000555555cd21d2 in do_cli (argc=4, argv=0x555556378cb0) at /path/to/php-src/sapi/cli/php_cli.c:1134 #7 0x0000555555cd2ab6 in main (argc=4, argv=0x555556378cb0) at /path/to/php-src/sapi/cli/php_cli.c:1366 ``` Perhaps the memory_limit should be a special case, and only be restored after everything else shuts down, and memory is freed? This is emitted as a notice to stdout when running https://github.com/phan/phan to self-analyze itself in php 8.1 with the default memory limit of 138 MB (phan generates cyclic data structures in some places, such as union type representations) Test script: --------------- <?php // Run this with php -d memory_limit=5M test.php class X { public $x; public function __construct() { $this->x = [$this]; } } gc_disable(); ini_set('memory_limit', '1G'); $y = []; for ($i = 0; $i < 20000; $i++) { $y[] = new X(); } $y[0]->y = &$y; $y[0]->z = $x; echo "Memory usage before shutting down: " . memory_get_usage() . "\n"; // Observed in php 8.1: // Warning: Failed to set memory limit to 5242880 bytes (Current memory usage is 12582912 bytes) in Unknown on line 0 Expected result: ---------------- No warning should be emitted during shutdown for a request Actual result: -------------- `Warning: Failed to set memory limit to 5242880 bytes (Current memory usage is 12582912 bytes) in Unknown on line 0` is emitted when php automatically tries to restore the system memory limit (`php -d memory_limit=5M`) -- Edit bug report at https://bugs.php.net/bug.php?id=81104&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=81104&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=81104&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=81104&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=81104&r=needscript Try newer version: https://bugs.php.net/fix.php?id=81104&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=81104&r=support Expected behavior: https://bugs.php.net/fix.php?id=81104&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=81104&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=81104&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=81104&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=81104&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=81104&r=dst IIS Stability: https://bugs.php.net/fix.php?id=81104&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=81104&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=81104&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=81104&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=81104&r=mysqlcfg

« previous php.bugs (#234201) next »