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

Fiber#transfer gets confused about thread owners #4920

chuckremes opened this Issue Dec 30, 2017 · 3 comments


None yet
2 participants
Copy link

chuckremes commented Dec 30, 2017


Provide at least:

  • JRuby version (jruby -v) and command line (flags, JRUBY_OPTS, etc)
  • Operating system and platform (e.g. uname -a)

Charless-Air:ruby-io cremes$ ruby -v
jruby (2.3.3) 2017-12-07 929fde8 Java HotSpot(TM) 64-Bit Server VM 25.144-b01 on 1.8.0_144-b01 +jit [darwin-x86_64]
Charless-Air:ruby-io cremes$ uname -a
Darwin Charless-Air 16.7.0 Darwin Kernel Version 16.7.0: Mon Nov 13 21:56:25 PST 2017; root:xnu-3789.72.11~1/RELEASE_X86_64 x86_64

Expected Behavior

  • Describe your expectation of how JRuby should behave, perhaps by showing how CRuby/MRI behaves.
  • Provide an executable Ruby script or a link to an example repository.

I should be able to ping pong between a thread's root fiber and a new fiber using Fiber#transfer. This behavior means that Ruby's Fiber is providing full coroutine behavior. However, it fails early with a complaint about transferring fibers between threads. This is NOT happening.

My guess is that since JRuby wraps a fiber in its own thread, there is some confusion over the proper "thread owner" ancestry of the fiber. That is, Ruby main thread T0 has root fiber F0 (wrapped in its own thread P0 by runtime). Main thread creates a new fiber F1 (wrapped in thread P1 by runtime) and attempts to transfer to it. Since both threads were created in Ruby thread T0, this should work. However, it's failing maybe due to the fiber(s) believing they were created by thread P0 or P1 (which are not visible from Ruby).

Full code to reproduce along with output from MRI 2.5.0, Rubinius 3.86, and JRuby

Actual Behavior

  • Describe or show the actual behavior.
  • Provide text or screen capture showing the behavior.

Charless-Air:ruby-io cremes$ ruby -v
rubinius 3.86.c109 (2.3.1 65a8656f 2017-12-29 5.0.0) [x86_64-darwin16.7.0]


This comment has been minimized.

Copy link

headius commented Jan 2, 2018

The problem appears to be transferring back to the main thread's "root fiber". Our data structure for Fiber tracks the "real" parent thread, and the root fiber was not being set up with any parent thread. Fixing this to make it its own parent appears to fix your example.

headius added a commit that referenced this issue Jan 2, 2018

@headius headius added this to the JRuby milestone Jan 2, 2018

@headius headius added the core label Jan 2, 2018


This comment has been minimized.

Copy link

headius commented Jan 2, 2018

I talked with @chuckremes on IRC and he will submit specs for this behavior to ruby/spec.


This comment has been minimized.

Copy link

chuckremes commented Jan 4, 2018

Spec accepted to ruby/spec: ruby/spec#579

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.