Add specs for where Fiber#transfer returns control - #1397
Open
sampokuokkanen wants to merge 3 commits into
Open
Conversation
A Fiber entered by Fiber#transfer has no resumer, so when it finishes or is killed, control goes to the innermost Fiber reachable from the root Fiber by following resumes, which is not necessarily the Fiber that transferred. Also covers a transferring Fiber that was itself entered by Fiber#raise.
Fiber#kill unwinds by transferring into the fiber, so it returns the fiber rather than nil, is a no-op on one that is already dead, and runs the ensure block while the fiber is still current and alive. An exception raised from that ensure block reaches the caller of kill, and killing a fiber belonging to another Thread raises FiberError. Also covers two cases where kill and transfer meet: killing a fiber from the fiber it transferred to, and killing a fiber whose ensure block transfers away.
Kill a Fiber twice and the second call returns false, not the Fiber. Running to completion does not count as killed, so one that ended on its own still returns itself. Raising into the Fiber that resumed you delivers the exception there and leaves you suspended. The resume it interrupts never returns, so the rest of the raising Fiber never runs.
sampokuokkanen
added a commit
to sampokuokkanen/jruby
that referenced
this pull request
Sep 10, 2026
Same examples as ruby/spec#1397, word for word, so the periodic sync of spec/ruby brings nothing new. They cover where control goes when a fiber entered by transfer finishes, is killed, or transferred from a fiber that Fiber#raise entered, plus what Fiber#kill returns and when it refuses. Three stay tagged: killing a fiber does not yet run its ensure block synchronously, so an exception raised there never reaches the caller and a fiber killed mid-transfer keeps running.
sampokuokkanen
added a commit
to sampokuokkanen/jruby
that referenced
this pull request
Sep 10, 2026
Same examples as the third commit on ruby/spec#1397, so the periodic sync of spec/ruby brings nothing new. Both are tagged: kill returns the fiber on a second call instead of false, and raising into the fiber that resumed us hands it our return value instead of leaving it suspended.
sampokuokkanen
added a commit
to sampokuokkanen/jruby
that referenced
this pull request
Sep 10, 2026
Same examples as ruby/spec#1397, word for word, so the periodic sync of spec/ruby brings nothing new. They cover where control goes when a fiber entered by transfer finishes, is killed, or transferred from a fiber that Fiber#raise entered, plus what Fiber#kill returns and when it refuses. Three stay tagged: killing a fiber does not yet run its ensure block synchronously, so an exception raised there never reaches the caller and a fiber killed mid-transfer keeps running.
sampokuokkanen
added a commit
to sampokuokkanen/jruby
that referenced
this pull request
Sep 10, 2026
Same examples as the third commit on ruby/spec#1397, so the periodic sync of spec/ruby brings nothing new. Both are tagged: kill returns the fiber on a second call instead of false, and raising into the fiber that resumed us hands it our return value instead of leaving it suspended.
sampokuokkanen
added a commit
to sampokuokkanen/jruby
that referenced
this pull request
Sep 10, 2026
Same examples as ruby/spec#1397, word for word, so the periodic sync of spec/ruby brings nothing new. They cover where control goes when a fiber entered by transfer finishes, is killed, or transferred from a fiber that Fiber#raise entered, plus what Fiber#kill returns and when it refuses. Three stay tagged: killing a fiber does not yet run its ensure block synchronously, so an exception raised there never reaches the caller and a fiber killed mid-transfer keeps running.
sampokuokkanen
added a commit
to sampokuokkanen/jruby
that referenced
this pull request
Sep 10, 2026
Same examples as the third commit on ruby/spec#1397, so the periodic sync of spec/ruby brings nothing new. Both are tagged: kill returns the fiber on a second call instead of false, and raising into the fiber that resumed us hands it our return value instead of leaving it suspended.
sampokuokkanen
added a commit
to sampokuokkanen/jruby
that referenced
this pull request
Sep 10, 2026
Same examples as ruby/spec#1397, word for word, so the periodic sync of spec/ruby brings nothing new. They cover where control goes when a fiber entered by transfer finishes, is killed, or transferred from a fiber that Fiber#raise entered, plus what Fiber#kill returns and when it refuses. Three stay tagged: killing a fiber does not yet run its ensure block synchronously, so an exception raised there never reaches the caller and a fiber killed mid-transfer keeps running.
sampokuokkanen
added a commit
to sampokuokkanen/jruby
that referenced
this pull request
Sep 10, 2026
Same examples as the third commit on ruby/spec#1397, so the periodic sync of spec/ruby brings nothing new. Both are tagged: kill returns the fiber on a second call instead of false, and raising into the fiber that resumed us hands it our return value instead of leaving it suspended.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Fiber entered by Fiber#transfer has no resumer, so when it finishes or is killed, control goes to the innermost Fiber reachable from the root Fiber by following resumes, which is not necessarily the Fiber that transferred. Also covers a transferring Fiber that was itself entered by Fiber#raise.