Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOID-5823 Use proper thread-local variables instead of fiber-local variables (Backport to 9.0) #5896

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

jamis
Copy link
Contributor

@jamis jamis commented Oct 24, 2024

(Backport from master to 9.0-stable)

MONGOID-5688 introduced a new way of processing cascading callbacks on embedded children, using Fibers to linearize the recursive calls. This proved very effective in avoiding SystemStackError exceptions caused by large numbers of embedded documents.

However, it turns out that Thread#[] and Thread#[]= get and set fiber-local variables, and not thread-local variables. Mongoid was using these methods quite a bit to set and manage its own internal state, which meant that any cascading callback on embedded children would be executed in a context that lacked all of Mongoid's state from the parent thread.

This PR fixes this issue by changing Mongoid's state handling routines (Mongoid::Threaded) to use actual thread-local storage (Thread#thread_variable_get and Thread#thread_variable_set) instead of the fiber-local variables.

… variables (mongodb#5891)

* MONGOID-5823 Use proper thread-local variables

Using fiber-local variables instead of thread-local variables has
the potential to introduce difficult bugs when Mongoid's internal
state is not visible to Fiber-wrapped cascading callbacks.

* remove cruft from an earlier experient

* *grumble* rubocop *grumble*

* fix test failures

* compensate for jruby
@jamis jamis requested a review from comandeo-mongo October 24, 2024 20:08
@jamis jamis merged commit 484092b into mongodb:9.0-stable Oct 25, 2024
66 of 68 checks passed
@jamis jamis deleted the 5823-thread-local-vars-9.0 branch October 25, 2024 14:10
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.

2 participants