Skip to content

Commit 3011d3d

Browse files
jmalvesheadius
authored andcommittedDec 12, 2017
Fix ThreadNexter shutdown killing nexter thread already executing a different task
Signed-off-by: Charles Oliver Nutter <headius@headius.com>
1 parent 719ef28 commit 3011d3d

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed
 

‎core/src/main/java/org/jruby/RubyEnumerator.java

+18-11
Original file line numberDiff line numberDiff line change
@@ -745,20 +745,28 @@ public synchronized void shutdown() {
745745

746746
// mark for death
747747
die = true;
748+
if (dissociateNexterThread(true)) doneObject = null;
749+
}
750+
751+
private synchronized boolean dissociateNexterThread(boolean interrupt) {
752+
Thread nexterThread = thread;
748753

749-
Thread myThread = thread;
750-
if (myThread != null) {
751-
if (DEBUG) System.out.println("clearing for shutdown");
754+
if (nexterThread != null) {
755+
if (DEBUG) System.out.println("dissociating nexter thread, interrupt: " + interrupt);
752756

753-
// we interrupt twice, to break out of iteration and
754-
// (potentially) break out of final exchange
755-
myThread.interrupt();
756-
myThread.interrupt();
757+
if (interrupt) {
758+
// we interrupt twice, to break out of iteration and
759+
// (potentially) break out of final exchange
760+
nexterThread.interrupt();
761+
nexterThread.interrupt();
762+
}
757763

758764
// release references
759765
thread = null;
760-
doneObject = null;
766+
return true;
761767
}
768+
769+
return false;
762770
}
763771

764772
@Override
@@ -910,9 +918,8 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block)
910918
if (!die) out.put(finalObject);
911919
}
912920
catch (InterruptedException ie) { /* ignore */ }
913-
}
914-
finally {
915-
thread = null; // disassociate this Nexter with the thread running it
921+
} finally {
922+
dissociateNexterThread(false); // disassociate this Nexter with the thread running it
916923
}
917924
}
918925
}

0 commit comments

Comments
 (0)
Please sign in to comment.