Skip to content

TypeError is raised when a thread is shutdown via Thread#kill #475

Description

@0x1eef

Hey.

I came across this potential bug earlier today.

I'm not sure if this is an Ruby, async, or io-events problem.
It includes all three. It involves a separate thread, Async::Reactor,
and the $! variable. Under certain circumstances it appears that
$! can be the number 8 and it can propagate as the target cause
for a raise call during thread shutdown initiated via Thread#kill.

In other words it appears raise(ex, cause: 8) is being called on the
thread that is being shutdown.

repro.rb

##
# Reproduction
# Ruby 4.0.6, async 2.45.1, io-event 1.21.1.

require "async"
Async::Scheduler.prepend(Module.new do
  define_method(:raise) do |*args, **kw|
    warn "scheduler#raise: args=#{args.inspect} kw=#{kw.inspect}"
    super(*args, **kw)
  end
end)

th = Thread.new do
  reactor = Async::Reactor.new
  reactor.async do
    reactor.async { sleep 30 } 
    sleep 0.05
  end
  reactor.run
end
th.report_on_exception = false
sleep 0.2
th.kill
##
# re-raises on caller thread
th.join(1)

puts "thread alive? #{th.alive?}"

##
# scheduler#raise: args=[#<Fiber ...>, Async::Cancel] kw={cause: 8}
# TypeError: exception object expected (on the killed thread)

Activity

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions