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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] I18n thread safety #568

Open
jerko-culina opened this issue May 26, 2021 · 3 comments
Open

[BUG] I18n thread safety #568

jerko-culina opened this issue May 26, 2021 · 3 comments

Comments

@jerko-culina
Copy link

馃憢 Hello to everyone. Not sure if this is the right place, sorry if I am wrong.

I have an issue with I18n thread safety (at least I think it is about that) on production after deploying newly initialized rails 6.1. application.
Our application consists of the API and admin dashboard. API is consumed by react app. Admin dashboard has been using by application administrators. On react side, we have support for over 10 languages, but on the admin dashboard, we only use English. After application deployment, administrators noticed that each time whey they refresh the admin dashboard they are getting the admin dashboard on another language.

I tried to debug it but without any success.
Anyone any advice/idea?

Not sure what info I should provide but by looking in the gem file we have:

Ruby 2.7.2
Rails 6.1.3.2
i18n (1.8.10)
i18n_data (0.10.0)
concurrent-ruby (1.1.8)
puma (5.1.0)

If more information is needed feel free to ask.
Sorry if this is the wrong place, feel free to redirect me to right one.

@jerko-culina
Copy link
Author

jerko-culina commented May 27, 2021

Additional information:
In active record model I have:

validates :name, presence: true

Each time when I try to submit an error message on the empty field I am getting an error message in another language. Most interesting thing is that it is happening on the localhost!

After setting locale explicitly did not have an issue anymore!

before_action :set_locale

def set_locale
  I18n.locale = I18n.default_locale
end

Seem like if you do not set locale explicitly it sets itself randomly!

@radar
Copy link
Collaborator

radar commented May 27, 2021

Please provide us with a test application that reproduces the issue.

@gstokkink
Copy link

gstokkink commented Jun 28, 2021

We ran into this issue with Rails 6.1 on production as well. Had to set I18n.locale explicitly for all requests, to prevent it from leaking over into other threads.

See also https://stackoverflow.com/questions/31649118/is-i18n-with-locale-threadsafe.

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

No branches or pull requests

3 participants