🧵🥅 Reraise receiver thread errors with caller's backtrace#691
Open
nevans wants to merge 3 commits into
Open
Conversation
Where it was located implied that it was part of the receiver thread code. But, although it does _coordinate_ with that code, it runs purely in the client thread.
Previously, when the receiver thread sends an exception to the client thread, it would be raised with the receiver thread's backtrace, which wasn't very useful. Now, a copy of the exception will be raised and it will use the current thread's `backtrace`. If the original has a backtrace or a cause, it will be set as the copy's `cause`.
Calling `Exception#set_backtrace` with `nil` doesn't appear to work for TruffleRuby 34.0.0. Issue reported: truffleruby/truffleruby#429 But calling `Exception#set_backtrace` with an array of `Thread::Backtrace::Location`s wasn't added until ruby 3.4. Also, minor difference, but that sets it to the location of `set_backtrace`, not the location of the `raise`. (But `caller_locations` drops toe current frame by default, which is maybe preferable anyway?)
f102688 to
5e7bef4
Compare
nevans
commented
Jun 6, 2026
| raise StandardError, "crashy crash" | ||
| end | ||
| end | ||
| assert_reraised(StandardError, imap:) do |
Collaborator
Author
There was a problem hiding this comment.
This looks like it might be a flaky test due to a threading race condition. It can either raise this, or it can raise IOError, "stream closed in another thread"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, when the receiver thread sent an exception to the client thread, it would be raised with the receiver thread's backtrace, which wasn't very useful.
Now a copy of the exception will be raised, and it will use the current thread's
backtrace. If the original has a backtrace or a cause, the original exception will be set as the copy'scause.