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 #5891

Merged
merged 6 commits into from
Oct 24, 2024

Conversation

jamis
Copy link
Contributor

@jamis jamis commented Oct 22, 2024

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.

jamis added 5 commits October 22, 2024 11:47
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.
@jamis jamis requested a review from comandeo-mongo October 22, 2024 20:52
@jamis jamis merged commit fc9b658 into mongodb:master Oct 24, 2024
66 of 68 checks passed
@jamis jamis deleted the 5823-thread-local-vars branch October 24, 2024 20:05
jamis added a commit to jamis/mongoid that referenced this pull request Oct 24, 2024
… 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 added a commit that referenced this pull request Oct 25, 2024
… variables (#5891) (#5896)

* 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
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