Skip to content

TracePoint does not support fiber_switch (Ruby 2.3+ compatibility) #9600

Closed

Description

@rkh

Environment Information

$ mise x ruby@jruby -- ruby -v 
jruby 10.1.0.0 (4.0.0) 2026-04-20 32f988b78c OpenJDK 64-Bit Server VM 26.0.2+10-55 on 26.0.2+10-55 +indy +jit [arm64-darwin]
$ uname -a
Darwin Konstantins-MBP.localdomain 25.5.0 Darwin Kernel Version 25.5.0: Tue Jun  9 22:28:34 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6041 arm64

No other dependencies are needed to run into this issue.

I found this by tracing which thread a fiber scheduler fiber belongs to.

Expected Behavior

Should trace fiber_switch events (introduced in Ruby 2.3.0)

triggered = false

TracePoint.trace(:fiber_switch) do |tp|
  triggered = true
end

Fiber.new { p triggered }.resume

Should print true

Actual Behavior

Raises an exception:

ArgumentError: unknown event: fiber_switch
  initialize at org/jruby/ext/tracepoint/TracePoint.java:65
         new at org/jruby/RubyClass.java:1058
       trace at org/jruby/ext/tracepoint/TracePoint.java:282
      <main> at play/trace.rb:3

Activity

  1. headius commented on Aug 21, 2026

    @headius
    Member

    Right you are. This does not seem to have coverage in rubyspec but we do have a related test from the CRuby suite excluded currently. I would not expect it to be difficult to implement.

  2. headius commented on Aug 21, 2026

    @headius
    Member

    A quick attempt here: #9603

  3. added this to the JRuby 10.1.x milestone on Aug 21, 2026
  4. rkh commented on Aug 22, 2026

    @rkh
    ContributorAuthor

    That was quick!

    FWIW, I'm not 100% sure the current patch fits my use case with the thread mismatch, since I'm trying to associate Thread.current with Fiber.scheduler and Fiber.current.

    BUUUUT I actually found a much better way to do that on JRuby, as these are exposed fairly neatly via getFiberCurrentThread and getScheduler (which will also work for fibers created before I could possibly set up a tracer).

  5. headius commented on Aug 23, 2026

    @headius
    Member

    JRuby 10.1.x is our more experimental edge version so I'm thinking I might attempt to make Thread.current always return the parent thread and we can see how that impacts real code.

    The workaround you found will work in any case. I will attempt to improve the behavior of Thread.current as well as merging the trace fix.

  6. linked a pull request that will close this issueImplement :fiber_switch trace event #9603on Sep 10, 2026
  7. headius commented on Sep 10, 2026

    @headius
    Member

    I'm going to call this fixed by #9603 even though Thread.current is still an open issue. Let me know if you run into other issues.

  8. rkh commented on Sep 10, 2026

    @rkh
    ContributorAuthor

    Thanks, will do! Thought I found another issue related to Thread.current (JRuby not permitting nested Fiber.schedule calls), but just checked, and that's already fixed on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions