Skip to content

Commit acd6e8a

Browse files
committed
Only set locking thread if no interrupts
If the lock is acquired but we are immediately interrupted by another thread, it will be unlocked while leaving the lockingThread field set. This will cause all future locks by other fibers on that thread to trigger a deadlock error, since the lock will appear to have been acquired by a different fiber on that thread. Patch by @yamam. Fixes jruby#9218
1 parent 0303464 commit acd6e8a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

core/src/main/java/org/jruby/ext/thread/Mutex.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ public IRubyObject lock(ThreadContext context) {
124124
}
125125
}
126126

127-
this.lockingThread = parentThread;
128-
129127
// always check for thread interrupts after acquiring lock
130128
try {
131129
thread.pollThreadEvents(context);
@@ -137,6 +135,9 @@ public IRubyObject lock(ThreadContext context) {
137135
Helpers.throwException(t);
138136
}
139137

138+
// set locking thread once successfully locked with no interrupts
139+
this.lockingThread = parentThread;
140+
140141
return this;
141142
}
142143

0 commit comments

Comments
 (0)