Open chendo opened 1 year ago
The program from the linked repository runs perfectly fine on WSL on my Surface Pro X (which also has ARM64), as well as on my AMD64 on both Windows (using hey) and WSL.
How often do you encounter this error?
Maybe there is some problem with mruby or Crystal on Mac, which triggers this, but I don't really have any options to test this. Based on the error message the crash seems to happen somewhere in the execution of the Ruby program, but the backtrace doesn't really go any further than that.
Perhaps running the Crystal program with valgrind could provide a bit more insight on where exactly the invalid memory access happens.
I was getting it every 2nd or 3rd run, although I did just have one where it didn't crash until the 5th run. It reads like to me that the crash itself is printing the backtrace, although I could be wrong there.
If I enable preview_mt
with crystal run -D preview_mt repro.cr
, then run wrk
, I sometimes get the same crash almost immediately, although I also often see other types of crashes as Anyolite doesn't support multithreading currently.
Unfortunately it seems valgrind is Linux-only, at least according to the Homebrew cask. I only have arm64 on on my Mac at the moment. I'll try to come up with a more reliable repro.
Alright, I've improved the repro so it's 100% reliable for me now, even on amd64. I've added a sleep 0.1
within the Crystal code that is being called from mruby
. It looks like the HTTP::Server
spawns multiple threads even without -D preview_mt
so I assume there's some shenanigans there. I do want to use anyolite
for a high throughput/concurrency scenario though, so not really sure how to progress.
Yep, now I can reproduce it as well.
The problem is apparently that two script calls interfere with each other, since they both use the same interpreter.
In that case, putting a mutex lock around the script line call should fix the problem, but it might limit the number of requests per second a bit, depending on the performance of the Ruby scripts (at least I see no significant difference between both cases if I use an empty handler
function).
Anyway, I could add some trivial guards to Anyolite to make it thread-safe for now. The limitation here is that mruby itself isn't thread-safe (and will probably never be).
Another solution will of course be support for multiple interpreters in parallel, but I will open a separate discussion thread for that (https://github.com/Anyolite/anyolite/discussions/28).
Under high load when running a simple program on my M1X Macbook Pro, I occasionally get an
Invalid memory access (signal 11)
crash.Reproduction repo: https://github.com/chendo/crystal-anyolite-crash-repro
Tested with Crystal 1.7.2, anyolite main (efe3337).
Interestingly enough, I could not reproduce the same issue inside an amd64 docker container (Rosetta).
Full crash log: