Skip to content

Commit

Permalink
do an alive check before raising exception on fiber's thread
Browse files Browse the repository at this point in the history
... otherwise leads to occassional NPE (seen on travis-ci) :

```
//             [exec]   1) A Fiber that has been abandoned cleans itself up properly
//             [exec]      Failure/Error: Unable to find org.jruby.ext.fiber.ThreadFiber.handleExceptionDuringExchange(ThreadFiber.java to read failed line
//             [exec]      Java::JavaLang::NullPointerException:
//             [exec]      # org.jruby.ext.fiber.ThreadFiber.handleExceptionDuringExchange(ThreadFiber.java:157)
//             [exec]      # org.jruby.ext.fiber.ThreadFiber.exchangeWithFiber(ThreadFiber.java:115)
//             [exec]      # org.jruby.ext.fiber.ThreadFiber.resume(ThreadFiber.java:90)
```
  • Loading branch information
kares committed Dec 5, 2016
1 parent b17bee6 commit 754fc04
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ext/fiber/ThreadFiber.java
Expand Up @@ -154,7 +154,7 @@ private static void handleExceptionDuringExchange(ThreadContext context, FiberDa
// Otherwise, we want to forward the exception to the target fiber
// since it has the ball
final ThreadFiber fiber = targetFiberData.fiber.get();
if ( fiber != null ) fiber.thread.raise(re.getException());
if ( fiber != null && fiber.alive() ) fiber.thread.raise(re.getException());
else LOG.warn("no fiber thread to raise: {}", re.getException().inspect(context));
}

Expand Down Expand Up @@ -239,7 +239,7 @@ public Map<Object, IRubyObject> getContextVariables() {
return thread.getContextVariables();
}

boolean alive() {
final boolean alive() {
return thread != null && thread.isAlive() && !data.queue.isShutdown();
}

Expand Down

0 comments on commit 754fc04

Please sign in to comment.