Skip to content

teardown with threads waiting gets ugly #5519

@kares

Description

@kares

tried to run a suite for adhearsion

  • git clone git@github.com:adhearsion/adhearsion.git
  • bundle install
  • rake spec

all is fine, except for an ugly warning printed from a thread (stucked) on teardown.

... so far haven't tried reducing the case to a minimal piece, but its fairly understandable
there's an initializer thread, seemingly, doing signal handling started on boot:

      self_read, self_write = IO.pipe

      %w(INT TERM HUP ALRM ABRT USR2).each do |sig|
        trap sig do
          self_write.puts sig
        end
      end

      Thread.new do
        begin
          while readable_io = IO.select([self_read])
            signal = readable_io.first[0].gets.strip
            handle_signal signal
          end
        rescue => e
          logger.error "Crashed reading signals"
          logger.error e
          exit 1
        end
      end

... and by the time the process exits (runtime.teardown()) :

    public void teardown() {
        // clear all thread-local context references
        localContext = new ThreadLocal<SoftReference<ThreadContext>>();

        // clear main context reference
        mainContext = null;

        // clear thread map
        rubyThreadMap.clear();
   }

the thread is still there trying to raise an exception, obviously hitting a null at mainContext

thinking JRuby should know its shutting down and not attempt to raise from threads that are still around ... as an improvement for the GH-3313 fix: 9f72b0c

JRuby 9.2.5.0 ends and prints a stack-trace :

Finished in 4 minutes 16.6 seconds (files took 9.34 seconds to load)
2541 examples, 0 failures, 27 pending

[Coveralls] Outside the Travis environment, not sending data.
Exception in thread "Ruby-0-Thread-3871: /home/kares/workspace/oss/adhearsion/lib/adhearsion/initializer.rb:95" Exception in thread "Ruby-0-Thread-3928: /home/kares/workspace/oss/adhearsion/lib/adhearsion/initializer.rb:95" Exception in thread "Ruby-0-Thread-3909: /home/kares/workspace/oss/adhearsion/lib/adhearsion/initializer.rb:95" java.lang.NullPointerException
	at org.jruby.internal.runtime.ThreadService.getMainThread(ThreadService.java:232)
	at org.jruby.RubyThread.exceptionRaised(RubyThread.java:1755)
	at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:112)
	at java.lang.Thread.run(Thread.java:748)
java.lang.NullPointerException
	at org.jruby.internal.runtime.ThreadService.getMainThread(ThreadService.java:232)
	at org.jruby.RubyThread.exceptionRaised(RubyThread.java:1755)
	at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:112)

JRuby 9.1.17.0 ends fine.

Finished in 4 minutes 11.2 seconds (files took 7.41 seconds to load)
2541 examples, 0 failures, 27 pending

[Coveralls] Outside the Travis environment, not sending data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions