Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@headius
Copy link
Member

@headius headius commented Jan 22, 2021

The logic here is designed to simulate a single execution stack by
forwarding any interrupt exceptions during a blocking fiber
operation to the target fiber, since it is "current" and should be
the one to handle any thread-level event. Originally the logic
forwarded any exception received while waiting for a fiber
response to the fiber and looped back to wait for a result. This
had the side effect of locking both the caller and the target
fibers into an endless exception-forwarding loop if the interrupt
were timed such that both were in their fiber queue push/pop
logic. Because both sides thought the other was the active side,
the exception would be forwarded forever.

The new logic will only attempt to forward an interrupt exception
once, with one additional wait for a valid response or a
propagated exception. If after forwarding an exception to the
target fiber the caller is again interrupted, the interrupt
exception at that point is either from the fiber (and should be
propagated) or it is a second interrupt and a good indication that
the caller needs to give up on the fiber and propagate the
exception.

This does open the possibility of abandoning a fiber that is still
running, but that should only happen if the caller gets
interrupted twice waiting on the fiber and the fiber does not
respond after the first interrupt.

See #6309

The logic here is designed to simulate a single execution stack by
forwarding any interrupt exceptions during a blocking fiber
operation to the target fiber, since it is "current" and should be
the one to handle any thread-level event. Originally the logic
forwarded any exception received while waiting for a fiber
response to the fiber and looped back to wait for a result. This
had the side effect of locking both the caller and the target
fibers into an endless exception-forwarding loop if the interrupt
were timed such that both were in their fiber queue push/pop
logic. Because both sides thought the other was the active side,
the exception would be forwarded forever.

The new logic will only attempt to forward an interrupt exception
once, with one additional wait for a valid response or a
propagated exception. If after forwarding an exception to the
target fiber the caller is again interrupted, the interrupt
exception at that point is either from the fiber (and should be
propagated) or it is a second interrupt and a good indication that
the caller needs to give up on the fiber and propagate the
exception.

This does open the possibility of abandoning a fiber that is still
running, but that should only happen if the caller gets
interrupted twice waiting on the fiber and the fiber does not
respond after the first interrupt.

See jruby#6309
@headius headius added this to the JRuby 9.2.15.0 milestone Jan 22, 2021
@headius headius merged commit 2f0aba3 into jruby:jruby-9.2 Jan 25, 2021
@headius headius deleted the fiber_edge_fixes branch January 25, 2021 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant