ruby-i18n / i18n

Internationalization (i18n) library for Ruby
MIT License
986 stars 411 forks source link

[BUG] I18n thread safety #568

Open jerko-culina opened 3 years ago

jerko-culina commented 3 years ago

👋 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 commented 3 years ago

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 commented 3 years ago

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

gstokkink commented 3 years ago

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.