Skip to content

Instantly share code, notes, and snippets.

@gmalkas
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmalkas/f858fb24c9c17fc7fd81 to your computer and use it in GitHub Desktop.
Save gmalkas/f858fb24c9c17fc7fd81 to your computer and use it in GitHub Desktop.
concurrent-ruby exceptions

The stack trace (it is partial, removed a bunch of stuff at the bottom):

Concurrent::TimerSet::Task.<=>(/services/0b26dd7b1416588272/.bundle/jruby/1.9/gems/concurrent-ruby-0.7.0-java/lib/concurrent/executor/timer_set.rb:106)
Concurrent::TimerSet::Task.<=>(/services/0b26dd7b1416588272/.bundle/jruby/1.9/gems/concurrent-ruby-0.7.0-java/lib/concurrent/executor/timer_set.rb:106)
java.util.PriorityQueue.siftUpComparable(java/util/PriorityQueue.java:637)
java.util.PriorityQueue.siftUp(java/util/PriorityQueue.java:629)
java.util.PriorityQueue.offer(java/util/PriorityQueue.java:329)
java.util.PriorityQueue.add(java/util/PriorityQueue.java:306)
java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:606)
Concurrent::JavaPriorityQueue.push(/services/0b26dd7b1416588272/.bundle/jruby/1.9/gems/concurrent-ruby-0.7.0-java/lib/concurrent/collection/priority_queue.rb:283)
Concurrent::JavaPriorityQueue.push(/services/0b26dd7b1416588272/.bundle/jruby/1.9/gems/concurrent-ruby-0.7.0-java/lib/concurrent/collection/priority_queue.rb:283)
Concurrent::TimerSet.post(/services/0b26dd7b1416588272/.bundle/jruby/1.9/gems/concurrent-ruby-0.7.0-java/lib/concurrent/executor/timer_set.rb:55)
Concurrent::TimerSet.post(/services/0b26dd7b1416588272/.bundle/jruby/1.9/gems/concurrent-ruby-0.7.0-java/lib/concurrent/executor/timer_set.rb:55)
org.jruby.ext.thread.Mutex.synchronize(org/jruby/ext/thread/Mutex.java:149)
Concurrent::TimerSet.post(/services/0b26dd7b1416588272/.bundle/jruby/1.9/gems/concurrent-ruby-0.7.0-java/lib/concurrent/executor/timer_set.rb:49)
Concurrent::TimerSet.post(/services/0b26dd7b1416588272/.bundle/jruby/1.9/gems/concurrent-ruby-0.7.0-java/lib/concurrent/executor/timer_set.rb:49)
Concurrent.timer(/services/0b26dd7b1416588272/.bundle/jruby/1.9/gems/concurrent-ruby-0.7.0-java/lib/concurrent/utility/timer.rb:17)
Concurrent.timer(/services/0b26dd7b1416588272/.bundle/jruby/1.9/gems/concurrent-ruby-0.7.0-java/lib/concurrent/utility/timer.rb:17)

According to the stack trace, the Ruby code responsible for the exception is the following: https://github.com/ruby-concurrency/concurrent-ruby/blob/master/lib/concurrent/executor/timer_set.rb#L106

The Java code calling this Ruby code is the following: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/java/util/PriorityQueue.java#637

In my logs, I got the previous stack trace, but the exception name is ' ' (whitespace).

I tried reproducing the issue by manually inserting a raise StandardError at different point of the Ruby library, and it seems that whenever the exception goes through some Java code, I cannot catch it in the calling Ruby code.

@gmalkas
Copy link
Author

gmalkas commented Nov 24, 2014

From a high-level perspective, the issue seems to be the following:

def method_a
  call_java_code
rescue => e
  p "Rescued #{e}"
end
public void JavaMethod() {
  callRubyMethodB();
}
def method_b
  raise StandardError
end

It seems I can't rescue the exception in Ruby method_a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment