php / php-src

The PHP Interpreter
https://www.php.net
Other
38.07k stars 7.74k forks source link

fatal: morestack on g0 #12021

Open leonardocustodio opened 1 year ago

leonardocustodio commented 1 year ago

Description

I'm getting this error when running a test that uses FFI to execute a go lib. It is probably related to this issue: https://github.com/golang/go/issues/62130 Not sure where the problem lies php or go

Resulted in this output:

fatal: morestack on g0

PHP Version

PHP 8.2.9

Operating System

macOS 13.4

iluuu1994 commented 1 year ago

Please provide some steps to reproduce the issue. It's hard to understand where the issue comes from without an example. From reading https://github.com/golang/go/issues/62130 they seem to have a clear grasp of what's causing this.

https://github.com/golang/go/issues/62130#issuecomment-1684431260

Currently the Go runtime assumes the C stack for each thread is contiguous and never change. It's stack bounds is recorded in the g0 of the thread. When the C (or PHP) code switches stacks, its SP will not be within the boundary of the original stack, therefore causing morestack on g0 error. This is not surprising.

I don't know exactly how FFI works under the hood, but it must allocate space for the stack somewhere for executing the given function. It sounds like Go assumes that the stack will never change. Thus different FFI calls with execution of morestack will break this assumption, as FFI likely allocates space for each FFI call independently. If that's the case, there's nothing we can do on our side.

leonardocustodio commented 1 year ago

Sure here are some steps to reproduce:

  1. Clone https://github.com/enjin/platform-core
  2. Have go installed
  3. composer install
  4. composer build-sr25519
  5. Then run all tests from phpunit

It will likely stop at "VerifyAccount" test with that error. Also if you just run that single test it will work, but running all of them it will not. Maybe related which what you said?

Btw this only happens on Apple Sillicon, I was not able to reproduce it on Ubuntu 22 (but maybe because my go version might be older? Let me update it on ubuntu to check if it will happen as well)

leonardocustodio commented 1 year ago

Yep, I've updated go, rebuilt the lib, and could not reproduce it on Ubuntu 22 with PHP 8.2.9. I can only reproduce it on Apple Sillicon using the same PHP and GO versions

leonardocustodio commented 1 year ago

I guess it is worth taking a look in this issue to get more clarification: https://github.com/dunglas/frankenphp/pull/171#issuecomment-1685219841

withinboredom commented 1 year ago

I can only reproduce it on Apple Sillicon using the same PHP and GO versions

Note that we cannot reproduce our issue on Apple Silicon, only AMD64. So they may be related, but in different ways.

leonardocustodio commented 1 year ago

Note that we cannot reproduce our issue on Apple Silicon, only AMD64. So they may be related, but in different ways.

I guess it could really be as he said https://github.com/golang/go/issues/62130#issuecomment-1690734255