-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fiber#alive? returns true even when already finished #4838
Comments
The NPE is a real bug that we should fix. The behavior of I'll take a look at both issues. In the future, it would be best to file them separately. |
* Store thread between null check and alive check to avoid NPE. * Use || for the conditions so any of them will indicate deadness. This allows the Fiber's queue shutdown, which happens before the last value is returned, to indicate that the thread is no longer alive (or soon will be truly dead).
This is fixed for JRuby 9.1.15.0. A better, albeit cumbersome workaround for you...this basically implements what I committed, but in Ruby: class org::jruby::ext::fiber::ThreadFiber
field_reader :thread
field_reader :data
class FiberData
field_reader :queue
end
end
class Fiber
def alive?
thread = JRuby.reference(self).thread
if thread == nil || !JRuby.reference(thread).isAlive || JRuby.reference(self).data.queue.isShutdown
return false
end
true
end
end |
Thank you, I have tried both the workaround and nightly build.
|
Hmm strange. My local env does have a couple spurious I'll try to figure out how these remaining cases would be happening. |
Once we push the final result on the resume queue the waiting thread may immediately resume, and see a Fiber that appears to be alive but which will actually soon be dead. By moving one of the death conditions before the final push, we will at least ensure the Fiber appears dead. There is an opposite side effect here, in that now a Fiber may appear to be dead a brief moment before it returns its last value, but this can only be observed from a third thread, which could not atomically know that both the final value had returned and the Fiber had declared itself dead. Fixes #4838.
I have committed an additional fix that makes your script run nearly (I'll come back to this) perfect. It should end up in tonight's nightly builds. Unfortunately, the fix is very deep inside our Fiber logic, which means there's no workaround I know of. I have on occasion, with or without this patch, seen an a FiberError claiming resume was called on a dead thread. I am still investigating that. |
It appears to be the |
Regarding the return value, I have confirmed that |
@satosho Thank you. I have not found a conclusive reason for the other failure, so I may file that as a separate issue and call this one fixed. |
It looks to be related to #1789 and #1949.
Environment
jruby 9.1.13.0 (2.3.3) 2017-09-06 8e1c115 Java HotSpot(TM) 64-Bit Server VM 25.151-b12 on 1.8.0_151-b12 +jit [mswin32-x86_64]
Windows 10 Home
Expected Behavior
Fiber#alive? returns false for all the calls in the following code.
On CRuby:
Actual Behavior
On JRuby, the results can be true.
The code sometimes runs into NullPointerException.
Workaround:
Fiber#alive? looks to return false as expected by adding a short sleep between resume and alive? calls.
The text was updated successfully, but these errors were encountered: