oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3.01k stars 184 forks source link

agoo: Exception in thread "SIGINT handler" java.lang.IllegalStateException: Can not create new threads in closing context. #1972

Open deepj opened 4 years ago

deepj commented 4 years ago
truffleruby 20.1.0-dev-8674e6f2, like ruby 2.6.5, GraalVM CE Native [x86_64-darwin]

To reproduce:

gem install agoo
agoo --help

Then Ctrl-C

Error:

Exception in thread "SIGINT handler" java.lang.IllegalStateException: Can not create new threads in closing context.
    at com.oracle.truffle.polyglot.PolyglotContextImpl.enterThreadChanged(PolyglotContextImpl.java:483)
    at com.oracle.truffle.polyglot.PolyglotEngineImpl.enter(PolyglotEngineImpl.java:1539)
    at com.oracle.truffle.polyglot.EngineAccessor$EngineImpl.enterInternalContext(EngineAccessor.java:630)
    at com.oracle.truffle.api.TruffleContext.enter(TruffleContext.java:152)
    at com.oracle.truffle.llvm.runtime.nodes.intrinsics.c.LLVMSignal$LLVMSignalHandler.handle(LLVMSignal.java:211)
    at sun.misc.Signal$1.run(Signal.java:212)
    at java.lang.Thread.run(Thread.java:748)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
olleolleolle commented 4 years ago

https://github.com/jruby/jruby/wiki/Signal-Handling this page from the JRuby wiki deals with signals. It has a note about the SIGINT kind of being "taken". Does that apply to the TruffleRuby situation, too?

Also does the same happen to JRuby?

eregon commented 4 years ago

TruffleRuby Native (used here) supports the same signals as MRI, and has the same signal semantics. In fact, it supports even more signal handlers. This is documented in https://github.com/oracle/truffleruby/blob/master/doc/user/compatibility.md#signals

https://github.com/ruby/spec/blob/ebdf0d1b06b39374a85baaae53771449ab1fe3d7/core/signal/trap_spec.rb#L121-L133 lists the reserved signals per Ruby implementation. TruffleRuby JVM cannot trap SIGUSR1 and SIGQUIT but otherwise can trap all other signals MRI can trap.

Also, TruffleRuby has the same default SIGINT handler as MRI.

So the error here is not about signal availability but somehow something going wrong when receiving that signal. It looks a signal is sent while the context is closing. https://github.com/oracle/truffleruby/issues/1823#issuecomment-603674696 looks like another, maybe related issue. I'll try to reproduce.

eregon commented 4 years ago

I can reproduce. The most likely reason it doesn't work here is that agoo registers the signal handlers not using Ruby Signal.trap but using C code: https://github.com/ohler55/agoo/blob/3a73cbfd6c5afc374d63c2cc07ffa4a8b8d39c97/ext/agoo/agoo.c#L119-L129

eregon commented 4 years ago

agoo --help just quits on MRI, not sure why it hangs on TruffleRuby.

Maybe related to agoo overriding the VM-reserved signal SIGVTALRM (it's also reserved on MRI), which might break many things: https://github.com/ohler55/agoo/blob/3a73cbfd6c5afc374d63c2cc07ffa4a8b8d39c97/ext/agoo/agoo.c#L123-L126

deepj commented 4 years ago

Closed due to I'm not welcome anymore in Ruby community