Skip to content

Handle Thread#kill during scheduler shutdown - #476

Merged
ioquatix merged 3 commits into
mainfrom
fix-thread-kill-cause
Sep 14, 2026
Merged

Handle Thread#kill during scheduler shutdown#476
ioquatix merged 3 commits into
mainfrom
fix-thread-kill-cause

Conversation

@samuel-williams-shopify

@samuel-williams-shopify samuel-williams-shopify commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Description

On affected CRuby versions, Thread#kill exposes the internal TAG_FATAL value (8) through $! while the fiber scheduler is closing. Async shutdown eventually passes that value to Task#cancel, where it is rejected as an exception cause and turns graceful thread termination into a TypeError.

Normalize non-exception cancellation causes at the Task#cancel boundary so Async falls back to its regular Async::Cancel::Cause. Add a regression test which kills a thread while its reactor owns a nested sleeping task and verifies that joining the thread does not raise.

Fixes #475.

The corresponding CRuby fixes are ruby/ruby#18808 and ruby/ruby#18809.

Testing

  • bundle exec bake test (543 tests, 1,196 assertions)
  • bundle exec rubocop lib/async/task.rb test/async/scheduler.rb

Assisted-By: devx/577dd101-056f-4573-9c18-d205cfd057f4
Assisted-By: devx/577dd101-056f-4573-9c18-d205cfd057f4
Assisted-By: devx/577dd101-056f-4573-9c18-d205cfd057f4
@ioquatix
ioquatix merged commit 33d40a8 into main Sep 14, 2026
77 of 81 checks passed
@ioquatix
ioquatix deleted the fix-thread-kill-cause branch September 14, 2026 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants