WordPress / playground-tools

GNU General Public License v2.0
133 stars 38 forks source link

wp-now: out of memory error when running for many hours #96

Open stokesman opened 1 year ago

stokesman commented 1 year ago

I often have wp-now running for days and after a while—I think usually > 48 hours—I get something like the following:

Fatal error: Out of memory (allocated 2097152) (tried to allocate 65536 bytes) in /var/www/html/wp-includes/rest-api/endpoints/class-wp-rest-controller.php on line 388

After that I can't recover the instance. I'm not sure what info I can provide to help illuminate the cause. I tracked down the debug.log in ~/.wp-now/… but not sure the output before the out of memory error is related.

debug.log portion ```log [08-Aug-2023 20:29:16 UTC] PHP Fatal error: Uncaught TypeError: property_exists(): Argument #1 ($object_or_class) must be of type object|string, array given in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php:2427 Stack trace: #0 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php(2427): property_exists(Array, 'Name') #1 [internal function]: WP_SQLite_Translator->{closure}(Array, 0) #2 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php(2430): array_filter(Array, Object(Closure), 1) #3 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php(2384): WP_SQLite_Translator->strip_sqlite_system_tables(Array) #4 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php(1381): WP_SQLite_Translator->get_information_schema_query('SELECT TABLE_NA...') #5 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php(736): WP_SQLite_Translator->execute_select() #6 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php(594): WP_SQLite_Translator->execute_mysql_query('SELECT TABLE_NA...') #7 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php(282): WP_SQLite_Translator->query('SELECT TABLE_NA...') #8 /var/www/html/wp-includes/class-wpdb.php(3099): WP_SQLite_DB->query('SELECT TABLE_NA...') #9 /var/www/html/wp-admin/includes/class-wp-site-health.php(3394): wpdb->get_results('SELECT TABLE_NA...', 'OBJECT_K') #10 /var/www/html/wp-admin/includes/class-wp-site-health.php(2469): WP_Site_Health->should_suggest_persistent_object_cache() #11 /var/www/html/wp-admin/includes/class-wp-site-health.php(194): WP_Site_Health->get_test_persistent_object_cache() #12 /var/www/html/wp-admin/includes/class-wp-site-health.php(3044): WP_Site_Health->perform_test(Array) #13 /var/www/html/wp-includes/class-wp-hook.php(308): WP_Site_Health->wp_cron_scheduled_check() #14 /var/www/html/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array) #15 /var/www/html/wp-includes/plugin.php(565): WP_Hook->do_action(Array) #16 /var/www/html/wp-cron.php(188): do_action_ref_array('wp_site_health_...', Array) #17 {main} thrown in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php on line 2427 [09-Aug-2023 00:17:39 UTC] PHP Fatal error: Out of memory (allocated 2097152) (tried to allocate 32768 bytes) in /var/www/html/wp-admin/includes/ajax-actions.php on line 2065 ```

Anyway, it’s a pretty small bother given how quick it is to spin up another instance. Still I thought the report might be appreciated.

I love using this compared to wp-env. Awesome work on it!

danielbachhuber commented 1 year ago

I often have wp-now running for days and after a while—I think usually > 48 hours

Wow! We definitely didn't test this scenario 😊 That's awesome!

Anyway, it’s a pretty small bother given how quick it is to spin up another instance. Still I thought the report might be appreciated.

Appreciate the report. There are probably a variety of memory leaks we'll eventually need to solve. We can keep this open as a collecting ground.

adamziel commented 11 months ago

First step would be to figure out whether the memory leak comes from php-wasm or wp-now. I worry it's the former, but the latter would be easier to fix.

Edit: Maybe it's both – there are a few related PRs:

stoph commented 7 months ago

I have been seeing this error as well recently. As I am developing a new plugin, I often (sometimes multiple times a day) get 'Out of Memory' errors in the browser and 'Maximum call stack size exceeded' in the CLI logs. Though sometime it's runs fine for the whole day.

CLI Errors $ wp-now start Starting the server...... directory: /Users/christoph/dev/api_mesh mode: wp-content php: 8.0 wp: latest WordPress latest folder already exists. Skipping download. SQLite folder already exists. Skipping download. Server running at http://localhost:8881 Trace: Error: Maximum call stack size exceeded at #handleRequest (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:67815:24) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async _NodePHP.run (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:67590:12) at async #dispatchToPHP (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:67202:14) at async PHPRequestHandler.request (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:67110:12) at async PHPBrowser.request (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:66904:22) at async file:///Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/main.js:900:20 { cause: Error: Rethrown at UnhandledRejectionsTarget.errorListener (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:67782:28) at [nodejs.internal.kHybridDispatch] (node:internal/event_target:807:20) at UnhandledRejectionsTarget.dispatchEvent (node:internal/event_target:742:26) at runtime.asm. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:66708:18) at invoke_viii (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:24600:7) ... 10 lines matching cause stack trace ... at ret. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:23875:33) { cause: RangeError: Maximum call stack size exceeded at (node:internal/event_target:100:16) at new Event (node:internal/event_target:111:14) at new ErrorEvent2 (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:66649:5) at runtime.asm. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:66709:13) at invoke_viii (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:24600:7) at zend_mm_safe_error (wasm://wasm/026ce4f6:wasm-function[1704]:0xedef0) at zend_mm_alloc_pages (wasm://wasm/026ce4f6:wasm-function[3233]:0x20467f) at zend_mm_alloc_small_slow (wasm://wasm/026ce4f6:wasm-function[609]:0x42834) at _emalloc (wasm://wasm/026ce4f6:wasm-function[108]:0x8713) at smart_str_erealloc (wasm://wasm/026ce4f6:wasm-function[116]:0x901e) at xbuf_format_converter (wasm://wasm/026ce4f6:wasm-function[4608]:0x2ef444) at php_printf_to_smart_str (wasm://wasm/026ce4f6:wasm-function[10117]:0x54a502) at zend_error_va_list (wasm://wasm/026ce4f6:wasm-function[4280]:0x2b4c30) at zend_error_noreturn (wasm://wasm/026ce4f6:wasm-function[145]:0xbf4d) at dynCall_viii (wasm://wasm/026ce4f6:wasm-function[11707]:0x5de475) at ret. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:23875:33) { cause: Error at Asyncify.handleSleep (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:24817:45) at _wasm_poll_socket (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:23729:21) at php_pollfd_for (wasm://wasm/026ce4f6:wasm-function[946]:0x8b1ef) at php_network_connect_socket (wasm://wasm/026ce4f6:wasm-function[5215]:0x36ad5f) at php_tcp_sockop_set_option (wasm://wasm/026ce4f6:wasm-function[10026]:0x5440b8) at php_openssl_sockop_set_option (wasm://wasm/026ce4f6:wasm-function[10154]:0x54e7e4) at _php_stream_set_option (wasm://wasm/026ce4f6:wasm-function[484]:0x326e7) at _php_stream_xport_create (wasm://wasm/026ce4f6:wasm-function[1643]:0xe7165) at zif_stream_socket_client (wasm://wasm/026ce4f6:wasm-function[7550]:0x463415) at ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER (wasm://wasm/026ce4f6:wasm-function[12978]:0x63869b) at execute_ex (wasm://wasm/026ce4f6:wasm-function[11537]:0x5d6006) at zend_execute (wasm://wasm/026ce4f6:wasm-function[3251]:0x2060a7) at zend_execute_scripts (wasm://wasm/026ce4f6:wasm-function[8642]:0x4e2f83) at dynCall_iiiii (wasm://wasm/026ce4f6:wasm-function[11715]:0x5debca) at ret. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:23875:33) at runtime.asm. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:66689:18) }, betterMessage: 'Maximum call stack size exceeded' } } at file:///Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/main.js:907:15 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) Exception in PromiseRejectCallback: node:internal/process/promises:153 maybeUnhandledPromises.set(promise, { ^ RangeError: Maximum call stack size exceeded Trace: Error: Maximum call stack size exceeded at #handleRequest (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:67815:24) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async _NodePHP.run (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:67590:12) at async #dispatchToPHP (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:67202:14) at async PHPRequestHandler.request (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:67110:12) at async PHPBrowser.request (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:66904:22) at async file:///Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/main.js:900:20 { cause: Error: Rethrown at UnhandledRejectionsTarget.errorListener (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:67782:28) at [nodejs.internal.kHybridDispatch] (node:internal/event_target:807:20) at UnhandledRejectionsTarget.dispatchEvent (node:internal/event_target:742:26) at runtime.asm. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:66708:18) at invoke_viii (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:24600:7) ... 8 lines matching cause stack trace ... at zend_error_noreturn (wasm://wasm/026ce4f6:wasm-function[145]:0xbf4d) at dynCall_viii (wasm://wasm/026ce4f6:wasm-function[11707]:0x5de475) at ret. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:23875:33) { cause: RangeError: Maximum call stack size exceeded at process.hrtime (node:internal/process/per_thread:78:3) at now (node:internal/perf/utils:18:22) at (node:internal/event_target:100:16) at new Event (node:internal/event_target:111:14) at new ErrorEvent2 (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:66649:5) at runtime.asm. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:66709:13) at invoke_viii (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:24600:7) at zend_mm_safe_error (wasm://wasm/026ce4f6:wasm-function[1704]:0xedef0) at zend_mm_alloc_pages (wasm://wasm/026ce4f6:wasm-function[3233]:0x20467f) at zend_mm_alloc_small_slow (wasm://wasm/026ce4f6:wasm-function[609]:0x42834) at _emalloc (wasm://wasm/026ce4f6:wasm-function[108]:0x8713) at smart_str_erealloc (wasm://wasm/026ce4f6:wasm-function[116]:0x901e) at xbuf_format_converter (wasm://wasm/026ce4f6:wasm-function[4608]:0x2ef444) at php_printf_to_smart_str (wasm://wasm/026ce4f6:wasm-function[10117]:0x54a502) at zend_error_va_list (wasm://wasm/026ce4f6:wasm-function[4280]:0x2b4c30) at zend_error_noreturn (wasm://wasm/026ce4f6:wasm-function[145]:0xbf4d) { cause: Error at Asyncify.handleSleep (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:24817:45) at _wasm_poll_socket (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:23729:21) at php_pollfd_for (wasm://wasm/026ce4f6:wasm-function[946]:0x8b1ef) at php_network_connect_socket (wasm://wasm/026ce4f6:wasm-function[5215]:0x36ad5f) at php_tcp_sockop_set_option (wasm://wasm/026ce4f6:wasm-function[10026]:0x5440b8) at php_openssl_sockop_set_option (wasm://wasm/026ce4f6:wasm-function[10154]:0x54e7e4) at _php_stream_set_option (wasm://wasm/026ce4f6:wasm-function[484]:0x326e7) at _php_stream_xport_create (wasm://wasm/026ce4f6:wasm-function[1643]:0xe7165) at zif_stream_socket_client (wasm://wasm/026ce4f6:wasm-function[7550]:0x463415) at ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER (wasm://wasm/026ce4f6:wasm-function[12978]:0x63869b) at execute_ex (wasm://wasm/026ce4f6:wasm-function[11537]:0x5d6006) at zend_execute (wasm://wasm/026ce4f6:wasm-function[3251]:0x2060a7) at zend_execute_scripts (wasm://wasm/026ce4f6:wasm-function[8642]:0x4e2f83) at dynCall_iiiii (wasm://wasm/026ce4f6:wasm-function[11715]:0x5debca) at ret. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:23875:33) at runtime.asm. (/Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/node_modules/@php-wasm/node/index.cjs:66689:18) }, betterMessage: 'Maximum call stack size exceeded' } } at file:///Users/christoph/.nvm/versions/node/v20.8.1/lib/node_modules/@wp-now/wp-now/main.js:907:15 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) ^C

Problem is, I can not consistently reproduce the crash. It happens during the course of me updating code, reloading, using the site, etc. But, not typically associated with me introducing an error in my code. Most of the time, I simply restart the server (wp-now start) and reload the existing tab, which works fine.