Skip to content

Queue#pop(timeout:) and SizedQueue#push(timeout:) receive Thread#kill / Thread#raise inside Thread.handle_interrupt(Object => :never) #10028

Closed

Description

@mensfeld

Environment: jruby 10.0.8.0, jruby 10.1.3.0, jruby 10.1.4.0-SNAPSHOT (5daf993); OpenJDK 21, Linux x86_64. Reference: CRuby 4.0.9.

def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
{ queue_pop_timeout: -> { Queue.new.pop(timeout: 1) },
  sized_push_timeout: -> { q = SizedQueue.new(1); q << 1; q.push(2, timeout: 1) },
  queue_pop: -> { q = Queue.new; Thread.new { sleep 1; q << :x }; q.pop },
  sleep: -> { sleep 1 } }.each do |name, work|
  log = Queue.new
  t = Thread.new do
    Thread.handle_interrupt(Object => :never) do
      t0 = now; work.call; log << [:block_done, (now - t0).round(2)]
    end
  ensure
    log << :ensure
  end
  sleep 0.3
  t.kill
  t.join
  puts "#{name}: #{log.size.times.map { log.pop }.inspect}"
end

CRuby 4.0.9:

queue_pop_timeout: [[:block_done, 1.0], :ensure]
sized_push_timeout: [[:block_done, 1.0], :ensure]
queue_pop: [[:block_done, 1.0], :ensure]
sleep: [[:block_done, 1.0], :ensure]

JRuby:

queue_pop_timeout: [:ensure]
sized_push_timeout: [:ensure]
queue_pop: [[:block_done, 1.0], :ensure]
sleep: [[:block_done, 0.3], :ensure]

Expected: the kill is deferred until the :never block ends, as with untimed Queue#pop. Actual: with a timeout, the kill ends the thread inside the masked block. t.raise("boom") behaves the same way. Related: masked
sleep 1 defers the kill but returns early (after 0.3s, return value 0); CRuby sleeps the full second.

Impact: code that uses handle_interrupt(Object => :never) to protect cleanup (for example, releasing a lock or draining a queue during shutdown) is interrupted part-way on JRuby.

Activity

  1. added this to the JRuby 10.1.4.0 milestone on Nov 13, 2026
  2. sampokuokkanen commented on Nov 13, 2026

    @sampokuokkanen
    Contributor

    Now on jruby-10.0 branch:

    queue_pop_timeout kill:   [[:block_done, 1.01], :ensure]
    queue_pop_timeout raise:  [[:block_done, 1.0], :ensure]
    sized_push_timeout kill:  [[:block_done, 1.01], :ensure]
    sized_push_timeout raise: [[:block_done, 1.01], :ensure]
    queue_pop kill:           [[:block_done, 1.01], :ensure]
    queue_pop raise:          [[:block_done, 1.0], :ensure]
    sleep kill:               [[:block_done, 0.31], :ensure]
    sleep raise:              [[:block_done, 0.3], :ensure]

    Sleep still left to fix.

  3. headius commented on Nov 17, 2026

    @headius
    Member

    Fixed by #10057 and #10064.

  4. kares commented on Nov 18, 2026

    @kares
    Member

    @headius have changed the milestone to 10.0.9.0 on both #10057 and #10064 not sure if 10.1.4.0 was intentional, it's still marked so here... maybe it's due the need to push out 10.1 release sooner?

  5. headius commented on Nov 18, 2026

    @headius
    Member

    The first fix was originally targeted at master so I think I got it in my head that both of them were going to master. Marking them for 10.0.9.0 is correct. This issue should probably also be changed and a duplicate issue created for 10.1 milestone.

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