arton / rjb

Ruby Java Bridge
https://www.artonx.org/collabo/backyard/?RubyJavaBridge
GNU Lesser General Public License v2.1
117 stars 34 forks source link

Crash when using puma forking #88

Open bmulholland opened 2 years ago

bmulholland commented 2 years ago

I posted a repro here: https://github.com/bmulholland/rjb-fork-crash

Short version is that, when trying to use puma workers, Rjb.load crashes. Output is:

objc[10802]: +[NSMethodSignature initialize] may have been in progress in another thread when fork() was called.
objc[10802]: +[NSMethodSignature initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
arton commented 2 years ago

Hi bmulholland I couldn't reproduce it on my X64 Linux. I suppose it causes JVM implementation for ARM. Any other Java application runs fine ? By the way, thank you for giving me the reproducable project. It' very helpful (sorry not for this case).

bmulholland commented 2 years ago

We have reproduced this crash (or at least, one very similar) on an Intel Mac as well. A workaround for us is to run the Rjb.load on every HTTP request, inside the worker. That workaround runs on all our machines, so there's no problem with JVM or anything. We do, however, need to use OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES for it to work, which seems dangerous, but at least it's only necessary on our development machines.

MatheusRich commented 1 year ago

To add to @bmulholland 's comment, here's the configuration added to puma.rb:

before_fork do
  Rjb.load # Remove all the Rjb.load calls in the app
end