Make translations loading thread-safe#644
Merged
radar merged 2 commits intoruby-i18n:masterfrom Dec 5, 2022
mensfeld:master
Merged
Make translations loading thread-safe#644radar merged 2 commits intoruby-i18n:masterfrom mensfeld:master
radar merged 2 commits intoruby-i18n:masterfrom
mensfeld:master
Conversation
radar
approved these changes
Dec 5, 2022
Contributor
|
hi @mensfeld I had an issue with loading not being thread safe: basically since eager load is disabled, two sidekiq threads are trying to load I18n at the same time resulting into this I'm going to eager load at bootup, but was wondering if I can just do MUTEX.synchronize do
Utils.deep_merge!(translations[locale], data)
endor maybe add the synchronize here: Line 247 in f2fb6a5 or wrap the entire what do you think is the best way please 🙏🏼 ( i wanna ask a real person, i dont wanna ask an AI. ty so much) |
chaadow
added a commit
to chaadow/i18n
that referenced
this pull request
Dec 28, 2025
ruby-i18n#644 (comment) When two threads lazy load the translations at the same time, there is a race condition while iterating through the `translations` hash. The first thread merges new values into the hash, and the second thread, while iterating, gets `can't add a new key into hash during iteration` The solution suggested is to use Mutex while merging the hash (which is a mutating action since we're using `merge!` instead of `merge` ) to prevent this from happening cc @mensfeld
Contributor
|
I went ahead and created this PR: #729 |
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.

close #643