Fix Reference#exec_recursive, #exec_recursive_clone to be fiber aware#15361
Merged
straight-shoota merged 3 commits intocrystal-lang:masterfrom Jan 23, 2025
Merged
Conversation
Recursion of the `#inspect` and `#pretty_print` methods is handled by a global hash, which is a per-thread global, but if any of these methods yield —which will happen because they're writing to an IO— another fiber running on the same thread will falsely detect a recursion if it inspects the same object. This patch moves `Reference#exec_recursive` methods as instances of `Fiber`, using a per-fiber hash instead of per-thread/process hash. References crystal-lang#15088
b8ab18c to
b845167
Compare
straight-shoota
approved these changes
Jan 21, 2025
Collaborator
Author
|
Thinking again about this: there's no need to move the implementation to Fiber, we only need to move the hash there. |
Member
|
This PR is OK with me, but is there anything covering the fiber-local variable usecase which is doable outside the stdlib? |
Collaborator
Author
|
@RX14 Nothing generic. We should open a new issue about that, it would be interesting to have something like a macro or annotation to keep fiber local data, without reopening |
Reference#exec_recursive[_clone] aren't fiber awareReference#exec_recursive, #exec_recursive_clone to be fiber aware
1 task
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.
Recursion of the
#inspectand#pretty_printmethods is handled by a global hash, which is a per-thread global, but if any of these methods yield —which will happen because they're writing to an IO— another fiber running on the same thread will falsely detect a recursion if it inspects the same object.This patch moves
Reference#exec_recursivemethods as instances ofFiber, using a per-fiber hash instead of per-thread/process hash.The example from #15088 now correctly prints: