Skip to content

Conversation

@chaadow
Copy link

@chaadow chaadow commented Dec 28, 2025

#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

Sentry screenshot with relevant stacktrace:
image

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
Copy link
Contributor

@mensfeld mensfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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