WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.63k stars 251 forks source link

Error: "unreachable" WASM instruction executed #1147

Closed remcotolsma closed 6 months ago

remcotolsma commented 7 months ago

The following code causes an Error: "unreachable" WASM instruction executed.:

\add_action(
    'init',
    function() {
        $data = new class() implements \IteratorAggregate {
            public function getIterator(): \Traversable {
                \wp_remote_get( 'https://httpbin.org/get' );

                $test = [
                    'option 1',
                    'option 2',
                    'option 3',
                ];

                return new \ArrayIterator( $test );
            }
        };

        $test = [
            (object) [ 'label' => '— Choose —' ],
            ...$data
        ];
    }
);

npx wp-now start --php 8.3
Starting the server......
directory: /Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms
mode: plugin
php: 8.3
wp: latest
WordPress latest folder already exists. Skipping download.
SQLite folder already exists. Skipping download.
Server running at http://localhost:8881
Trace: Error:
"unreachable" WASM instruction executed.

The typical reason is a PHP function missing from the ASYNCIFY_ONLY
list when building PHP.wasm.

You will need to file a new issue in the WordPress Playground repository
and paste this error message there:

https://github.com/WordPress/wordpress-playground/issues/new

If you're a core developer, the typical fix is to:

* Isolate a minimal reproduction of the error
* Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
* Run 'npm run fix-asyncify'
* Commit the changes, push to the repo, release updated NPM packages

Below is a list of all the PHP functions found in the stack trace to
help with the minimal reproduction. If they're all already listed in
the Dockerfile, you'll need to trigger this error again with long stack
traces enabled. In node.js, you can do it using the --stack-trace-limit=100
CLI option:

    * php_pollfd_for
    * php_network_connect_socket
    * php_tcp_sockop_set_option
    * php_openssl_sockop_set_option
    * _php_stream_set_option
    * _php_stream_xport_create
    * zif_stream_socket_client
    * ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER
    * execute_ex
    * zend_call_function

    at #handleRequest (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:69312:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async _NodePHP.run (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:69045:14)
    at async #dispatchToPHP (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68581:14)
    at async PHPRequestHandler.request (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68484:14)
    at async PHPBrowser.request (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68326:22)
    at async file:///Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@wp-now/wp-now/main.js:912:20 {
  cause: Error: Rethrown
      at UnhandledRejectionsTarget.errorListener (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:69278:28)
      at [nodejs.internal.kHybridDispatch] (node:internal/event_target:822:20)
      at UnhandledRejectionsTarget.dispatchEvent (node:internal/event_target:757:26)
      at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68069:20)
      at invoke_iiiii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10610:14)
      at php_execute_script (wasm://wasm/02b5939a:wasm-function[10795]:0x5bf836)
      at dynCall_ii (wasm://wasm/02b5939a:wasm-function[12431]:0x65fa1a)
      at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
      at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
      at invoke_ii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10533:14)
      at wasm_sapi_handle_request (wasm://wasm/02b5939a:wasm-function[9415]:0x554538)
      at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
      at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
      at Object.ccall (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9955:20)
      at exitCode (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:69287:53)
      at new Promise (<anonymous>) {
    cause: RuntimeError: unreachable
        at zend_std_write_property (wasm://wasm/02b5939a:wasm-function[994]:0x92d14)
        at zend_default_exception_new (wasm://wasm/02b5939a:wasm-function[9040]:0x5415c5)
        at object_init_ex (wasm://wasm/02b5939a:wasm-function[191]:0x12787)
        at zend_throw_exception_zstr (wasm://wasm/02b5939a:wasm-function[3283]:0x21258a)
        at zend_throw_exception (wasm://wasm/02b5939a:wasm-function[224]:0x1614e)
        at zend_throw_exception_ex (wasm://wasm/02b5939a:wasm-function[139]:0xaeab)
        at zend_user_it_get_new_iterator (wasm://wasm/02b5939a:wasm-function[8916]:0x5372d5)
        at ZEND_ADD_ARRAY_UNPACK_SPEC_HANDLER (wasm://wasm/02b5939a:wasm-function[13993]:0x6df9c1)
        at execute_ex (wasm://wasm/02b5939a:wasm-function[12242]:0x655c2f)
        at zend_execute (wasm://wasm/02b5939a:wasm-function[3335]:0x216beb)
        at zend_execute_scripts (wasm://wasm/02b5939a:wasm-function[9030]:0x540a71)
        at dynCall_iiiii (wasm://wasm/02b5939a:wasm-function[12428]:0x65f7b3)
        ... 2 lines matching cause stack trace ...
        at invoke_iiiii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10610:14)
        at php_execute_script (wasm://wasm/02b5939a:wasm-function[10795]:0x5bf836) {
      cause: Error
          at Asyncify.handleSleep (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10749:45)
          at _wasm_poll_socket (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9627:21)
          at php_pollfd_for (wasm://wasm/02b5939a:wasm-function[967]:0x90aa8)
          at php_network_connect_socket (wasm://wasm/02b5939a:wasm-function[5415]:0x397c22)
          at php_tcp_sockop_set_option (wasm://wasm/02b5939a:wasm-function[10486]:0x5a4e76)
          at php_openssl_sockop_set_option (wasm://wasm/02b5939a:wasm-function[10621]:0x5b04ec)
          at _php_stream_set_option (wasm://wasm/02b5939a:wasm-function[487]:0x35fda)
          at dynCall_iiiii (wasm://wasm/02b5939a:wasm-function[12428]:0x65f7b3)
          at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
          at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
          at invoke_iiiii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10610:14)
          at _php_stream_xport_create (wasm://wasm/02b5939a:wasm-function[1712]:0xf1fa3)
          at zif_stream_socket_client (wasm://wasm/02b5939a:wasm-function[7893]:0x4b9abe)
          at ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER (wasm://wasm/02b5939a:wasm-function[13744]:0x6c0798)
          at execute_ex (wasm://wasm/02b5939a:wasm-function[12242]:0x655c2f)
          at zend_call_function (wasm://wasm/02b5939a:wasm-function[462]:0x32c3a)
    },
    betterMessage: '\n' +
      '"unreachable" WASM instruction executed.\n' +
      '\n' +
      'The typical reason is a PHP function missing from the ASYNCIFY_ONLY\n' +
      'list when building PHP.wasm.\n' +
      '\n' +
      'You will need to file a new issue in the WordPress Playground repository\n' +
      'and paste this error message there:\n' +
      '\n' +
      'https://github.com/WordPress/wordpress-playground/issues/new\n' +
      '\n' +
      "If you're a core developer, the typical fix is to:\n" +
      '\n' +
      '* Isolate a minimal reproduction of the error\n' +
      '* Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository\n' +
      "* Run 'npm run fix-asyncify'\n" +
      '* Commit the changes, push to the repo, release updated NPM packages\n' +
      '\n' +
      'Below is a list of all the PHP functions found in the stack trace to\n' +
      "help with the minimal reproduction. If they're all already listed in\n" +
      "the Dockerfile, you'll need to trigger this error again with long stack\n" +
      'traces enabled. In node.js, you can do it using the --stack-trace-limit=100\n' +
      'CLI option: \n' +
      '\n' +
      '    * php_pollfd_for\n' +
      '    * php_network_connect_socket\n' +
      '    * php_tcp_sockop_set_option\n' +
      '    * php_openssl_sockop_set_option\n' +
      '    * _php_stream_set_option\n' +
      '    * _php_stream_xport_create\n' +
      '    * zif_stream_socket_client\n' +
      '    * ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER\n' +
      '    * execute_ex\n' +
      '    * zend_call_function\n'
  }
}
    at file:///Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@wp-now/wp-now/main.js:919:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

  WASM ERROR
  table index is out of bounds

wasm://wasm/02b5939a:1

RuntimeError: table index is out of bounds
    at dynCall_iiiii (wasm://wasm/02b5939a:wasm-function[12428]:0x65f7b3)
    ... 2 lines matching cause stack trace ...
    at invoke_iiiii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10610:14)
    at php_execute_script (wasm://wasm/02b5939a:wasm-function[10795]:0x5bf836)
    at dynCall_ii (wasm://wasm/02b5939a:wasm-function[12431]:0x65fa1a)
    at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
    at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
    at invoke_ii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10533:14)
    at wasm_sapi_handle_request (wasm://wasm/02b5939a:wasm-function[9415]:0x554538)
    at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
    at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
    at Object.doRewind (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9845:14)
    at /Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9868:45
    at /Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9694:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: Error
      at Asyncify.handleSleep (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10749:45)
      at _wasm_poll_socket (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9627:21)
      at php_pollfd_for (wasm://wasm/02b5939a:wasm-function[967]:0x90aa8)
      at php_network_connect_socket (wasm://wasm/02b5939a:wasm-function[5415]:0x397c22)
      at php_tcp_sockop_set_option (wasm://wasm/02b5939a:wasm-function[10486]:0x5a4e76)
      at php_openssl_sockop_set_option (wasm://wasm/02b5939a:wasm-function[10621]:0x5b04ec)
      at _php_stream_set_option (wasm://wasm/02b5939a:wasm-function[487]:0x35fda)
      at dynCall_iiiii (wasm://wasm/02b5939a:wasm-function[12428]:0x65f7b3)
      at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
      at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
      at invoke_iiiii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10610:14)
      at _php_stream_xport_create (wasm://wasm/02b5939a:wasm-function[1712]:0xf1fa3)
      at zif_stream_socket_client (wasm://wasm/02b5939a:wasm-function[7893]:0x4b9abe)
      at ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER (wasm://wasm/02b5939a:wasm-function[13744]:0x6c0798)
      at execute_ex (wasm://wasm/02b5939a:wasm-function[12242]:0x655c2f)
      at zend_call_function (wasm://wasm/02b5939a:wasm-function[462]:0x32c3a)
}

Node.js v21.6.2
➜  wp-pronamic-pay-with-mollie-for-gravity-forms git:(main) ✗ npx wp-now start --php 8.3
Starting the server......
directory: /Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms
mode: plugin
php: 8.3
wp: latest
WordPress latest folder already exists. Skipping download.
SQLite folder already exists. Skipping download.
Error:
"unreachable" WASM instruction executed.

The typical reason is a PHP function missing from the ASYNCIFY_ONLY
list when building PHP.wasm.

You will need to file a new issue in the WordPress Playground repository
and paste this error message there:

https://github.com/WordPress/wordpress-playground/issues/new

If you're a core developer, the typical fix is to:

* Isolate a minimal reproduction of the error
* Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
* Run 'npm run fix-asyncify'
* Commit the changes, push to the repo, release updated NPM packages

Below is a list of all the PHP functions found in the stack trace to
help with the minimal reproduction. If they're all already listed in
the Dockerfile, you'll need to trigger this error again with long stack
traces enabled. In node.js, you can do it using the --stack-trace-limit=100
CLI option:

    * php_pollfd_for
    * php_network_connect_socket
    * php_tcp_sockop_set_option
    * php_openssl_sockop_set_option
    * _php_stream_set_option
    * _php_stream_xport_create
    * zif_stream_socket_client
    * ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER
    * execute_ex
    * zend_call_function

    at #handleRequest (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:69312:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async _NodePHP.run (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:69045:14)
    at async #dispatchToPHP (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68581:14)
    at async PHPRequestHandler.request (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68484:14)
    at async PHPBrowser.request (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68326:22)
    at async ca (file:///Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@wp-playground/blueprints/index.js:1406:95)
    at async startWPNow (file:///Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@wp-now/wp-now/main.js:607:3)
    at async startServer (file:///Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@wp-now/wp-now/main.js:873:42)
    at async Object.handler (file:///Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@wp-now/wp-now/main.js:1069:25) {
  cause: Error: Rethrown
      at UnhandledRejectionsTarget.errorListener (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:69278:28)
      at [nodejs.internal.kHybridDispatch] (node:internal/event_target:822:20)
      at UnhandledRejectionsTarget.dispatchEvent (node:internal/event_target:757:26)
      at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68069:20)
      at invoke_iiiii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10610:14)
      at php_execute_script (wasm://wasm/02b5939a:wasm-function[10795]:0x5bf836)
      at dynCall_ii (wasm://wasm/02b5939a:wasm-function[12431]:0x65fa1a)
      at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
      at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
      at invoke_ii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10533:14)
      at wasm_sapi_handle_request (wasm://wasm/02b5939a:wasm-function[9415]:0x554538)
      at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
      at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
      at Object.ccall (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9955:20)
      at exitCode (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:69287:53)
      at new Promise (<anonymous>) {
    cause: RuntimeError: unreachable
        at zend_std_write_property (wasm://wasm/02b5939a:wasm-function[994]:0x92d14)
        at zend_default_exception_new (wasm://wasm/02b5939a:wasm-function[9040]:0x5415c5)
        at object_init_ex (wasm://wasm/02b5939a:wasm-function[191]:0x12787)
        at zend_throw_exception_zstr (wasm://wasm/02b5939a:wasm-function[3283]:0x21258a)
        at zend_throw_exception (wasm://wasm/02b5939a:wasm-function[224]:0x1614e)
        at zend_throw_exception_ex (wasm://wasm/02b5939a:wasm-function[139]:0xaeab)
        at zend_user_it_get_new_iterator (wasm://wasm/02b5939a:wasm-function[8916]:0x5372d5)
        at ZEND_ADD_ARRAY_UNPACK_SPEC_HANDLER (wasm://wasm/02b5939a:wasm-function[13993]:0x6df9c1)
        at execute_ex (wasm://wasm/02b5939a:wasm-function[12242]:0x655c2f)
        at zend_execute (wasm://wasm/02b5939a:wasm-function[3335]:0x216beb)
        at zend_execute_scripts (wasm://wasm/02b5939a:wasm-function[9030]:0x540a71)
        at dynCall_iiiii (wasm://wasm/02b5939a:wasm-function[12428]:0x65f7b3)
        ... 2 lines matching cause stack trace ...
        at invoke_iiiii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10610:14)
        at php_execute_script (wasm://wasm/02b5939a:wasm-function[10795]:0x5bf836) {
      cause: Error
          at Asyncify.handleSleep (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10749:45)
          at _wasm_poll_socket (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9627:21)
          at php_pollfd_for (wasm://wasm/02b5939a:wasm-function[967]:0x90aa8)
          at php_network_connect_socket (wasm://wasm/02b5939a:wasm-function[5415]:0x397c22)
          at php_tcp_sockop_set_option (wasm://wasm/02b5939a:wasm-function[10486]:0x5a4e76)
          at php_openssl_sockop_set_option (wasm://wasm/02b5939a:wasm-function[10621]:0x5b04ec)
          at _php_stream_set_option (wasm://wasm/02b5939a:wasm-function[487]:0x35fda)
          at dynCall_iiiii (wasm://wasm/02b5939a:wasm-function[12428]:0x65f7b3)
          at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
          at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
          at invoke_iiiii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10610:14)
          at _php_stream_xport_create (wasm://wasm/02b5939a:wasm-function[1712]:0xf1fa3)
          at zif_stream_socket_client (wasm://wasm/02b5939a:wasm-function[7893]:0x4b9abe)
          at ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER (wasm://wasm/02b5939a:wasm-function[13744]:0x6c0798)
          at execute_ex (wasm://wasm/02b5939a:wasm-function[12242]:0x655c2f)
          at zend_call_function (wasm://wasm/02b5939a:wasm-function[462]:0x32c3a)
    },
    betterMessage: '\n' +
      '"unreachable" WASM instruction executed.\n' +
      '\n' +
      'The typical reason is a PHP function missing from the ASYNCIFY_ONLY\n' +
      'list when building PHP.wasm.\n' +
      '\n' +
      'You will need to file a new issue in the WordPress Playground repository\n' +
      'and paste this error message there:\n' +
      '\n' +
      'https://github.com/WordPress/wordpress-playground/issues/new\n' +
      '\n' +
      "If you're a core developer, the typical fix is to:\n" +
      '\n' +
      '* Isolate a minimal reproduction of the error\n' +
      '* Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository\n' +
      "* Run 'npm run fix-asyncify'\n" +
      '* Commit the changes, push to the repo, release updated NPM packages\n' +
      '\n' +
      'Below is a list of all the PHP functions found in the stack trace to\n' +
      "help with the minimal reproduction. If they're all already listed in\n" +
      "the Dockerfile, you'll need to trigger this error again with long stack\n" +
      'traces enabled. In node.js, you can do it using the --stack-trace-limit=100\n' +
      'CLI option: \n' +
      '\n' +
      '    * php_pollfd_for\n' +
      '    * php_network_connect_socket\n' +
      '    * php_tcp_sockop_set_option\n' +
      '    * php_openssl_sockop_set_option\n' +
      '    * _php_stream_set_option\n' +
      '    * _php_stream_xport_create\n' +
      '    * zif_stream_socket_client\n' +
      '    * ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER\n' +
      '    * execute_ex\n' +
      '    * zend_call_function\n'
  }
}
Failed to start the server:
"unreachable" WASM instruction executed.

The typical reason is a PHP function missing from the ASYNCIFY_ONLY
list when building PHP.wasm.

You will need to file a new issue in the WordPress Playground repository
and paste this error message there:

https://github.com/WordPress/wordpress-playground/issues/new

If you're a core developer, the typical fix is to:

* Isolate a minimal reproduction of the error
* Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
* Run 'npm run fix-asyncify'
* Commit the changes, push to the repo, release updated NPM packages

Below is a list of all the PHP functions found in the stack trace to
help with the minimal reproduction. If they're all already listed in
the Dockerfile, you'll need to trigger this error again with long stack
traces enabled. In node.js, you can do it using the --stack-trace-limit=100
CLI option:

    * php_pollfd_for
    * php_network_connect_socket
    * php_tcp_sockop_set_option
    * php_openssl_sockop_set_option
    * _php_stream_set_option
    * _php_stream_xport_create
    * zif_stream_socket_client
    * ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER
    * execute_ex
    * zend_call_function

  WASM ERROR
  table index is out of bounds

wasm://wasm/02b5939a:1

RuntimeError: table index is out of bounds
    at dynCall_iiiii (wasm://wasm/02b5939a:wasm-function[12428]:0x65f7b3)
    ... 2 lines matching cause stack trace ...
    at invoke_iiiii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10610:14)
    at php_execute_script (wasm://wasm/02b5939a:wasm-function[10795]:0x5bf836)
    at dynCall_ii (wasm://wasm/02b5939a:wasm-function[12431]:0x65fa1a)
    at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
    at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
    at invoke_ii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10533:14)
    at wasm_sapi_handle_request (wasm://wasm/02b5939a:wasm-function[9415]:0x554538)
    at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
    at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
    at Object.doRewind (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9845:14)
    at /Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9868:45
    at /Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9694:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: Error
      at Asyncify.handleSleep (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10749:45)
      at _wasm_poll_socket (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9627:21)
      at php_pollfd_for (wasm://wasm/02b5939a:wasm-function[967]:0x90aa8)
      at php_network_connect_socket (wasm://wasm/02b5939a:wasm-function[5415]:0x397c22)
      at php_tcp_sockop_set_option (wasm://wasm/02b5939a:wasm-function[10486]:0x5a4e76)
      at php_openssl_sockop_set_option (wasm://wasm/02b5939a:wasm-function[10621]:0x5b04ec)
      at _php_stream_set_option (wasm://wasm/02b5939a:wasm-function[487]:0x35fda)
      at dynCall_iiiii (wasm://wasm/02b5939a:wasm-function[12428]:0x65f7b3)
      at ret.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:9762:33)
      at runtime.asm.<computed> (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:68056:18)
      at invoke_iiiii (/Users/remco/Projects/wp-pronamic-pay-with-mollie-for-gravity-forms/node_modules/@php-wasm/node/index.cjs:10610:14)
      at _php_stream_xport_create (wasm://wasm/02b5939a:wasm-function[1712]:0xf1fa3)
      at zif_stream_socket_client (wasm://wasm/02b5939a:wasm-function[7893]:0x4b9abe)
      at ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_USED_HANDLER (wasm://wasm/02b5939a:wasm-function[13744]:0x6c0798)
      at execute_ex (wasm://wasm/02b5939a:wasm-function[12242]:0x655c2f)
      at zend_call_function (wasm://wasm/02b5939a:wasm-function[462]:0x32c3a)
}

Node.js v21.6.2
adamziel commented 6 months ago

Related: https://github.com/WordPress/wordpress-playground/issues/273

@bgrgicak it would be nice to also test for generators and reaching for network resources between yields

bgrgicak commented 6 months ago

I can take a look at this one next week.

bgrgicak commented 6 months ago

I wasn't able to recreate the error using the above code, but this causes a similar issue:

    php.writeFile(
        joinPaths(docroot, 'test.php'),
        `<?php
            $data = new class() implements IteratorAggregate {
                public function getIterator(): Traversable {
                    post_message_to_js( 'test' );
                    return new ArrayIterator( [] );
                }
            };
            echo json_encode( [
                ...$data
            ] );
        `
    );
adamziel commented 6 months ago

@remcotolsma did that solve the problem for you? The latest version is now deployed to https://playground.wordpress.net/

rvdsteege commented 6 months ago

As a colleague of @remcotolsma, I followed along and it seems that the additions to ASYNCIFY_ONLY indeed resolve the issue with iterators. Thanks!