Skip to content
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

Rework raise interrupt handling at fiber edges #6538

Merged
merged 1 commit into from Jan 25, 2021

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
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.

None yet

1 participant