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

Local and available local #229

Closed
kaluznyo opened this issue Dec 30, 2024 · 18 comments · Fixed by #231
Closed

Local and available local #229

kaluznyo opened this issue Dec 30, 2024 · 18 comments · Fixed by #231

Comments

@kaluznyo
Copy link

Hi,

I don't know if MissionControl is the guilty, but since I have installed, I get random error on my main app, and crash with :
:fr is not a valid locale

On my app I've this :
I18n.load_path += Dir[Rails.root.join("config", "locale", "*.{rb,yml}")] config.i18n.default_locale = :fr
Can be related to MissionControl code in https://github.com/rails/mission_control-jobs/blob/66f829f795c1f96a33484fbe410a2bd4e9f69640/lib/mission_control/jobs/i18n_config.rb.

@rosa
Copy link
Member

rosa commented Dec 30, 2024

Hey @kaluznyo, what version of MIssion Control are you using?

@kaluznyo
Copy link
Author

Sorry ! 1.0.1, and rails 8.0.1

@rosa
Copy link
Member

rosa commented Dec 30, 2024

Huh, 1.0.1 should have a fix for that problem... could you copy the full trace from the error?

@kaluznyo
Copy link
Author

The error and the trace is on my 'main' app, when it crash, mission control is still alive

https://gist.github.com/kaluznyo/e99d274c971c4a37e534e43aa2573535

@rosa
Copy link
Member

rosa commented Dec 30, 2024

Oh, interesting... it's different from the error I fixed in version 1.0.1. 🤔 The code here is only used in Mission Control's controllers, so it shouldn't affect the code path in your error trace 🤔

Could you check what locale is being passed to the translate call in /PROJECT_ROOT/app/views/tasks/index.html.erb:17?

@kaluznyo
Copy link
Author

I just use the translate (t()) rails method on line 17. I suppose it's related to this, because when I put in production with Mission Control tab open, my main app crash. If I put in production without Mission Control open, it's work. My intuition, says the available locals is redefined globally by Mission Control. But if you say it's not possible, I'm probably wrong !

@rosa
Copy link
Member

rosa commented Dec 30, 2024

I put in production with Mission Control tab open, my main app crash. If I put in production without Mission Control open, it's work.

Huh, so do you mean that in both cases, Mission Control is installed in your app, just that in the second case you're not using it? So strange!

@kaluznyo
Copy link
Author

Ok, I reproduce in local, start my server, without any tab open on my localhost, got to /jobs (url for mission control), and then go to my main page where I have I18n. Crash

@rosa
Copy link
Member

rosa commented Dec 30, 2024

@kaluznyo, could I get more details on how you have configured Mission Control? The routes where it's mounted and all that?

@kaluznyo
Copy link
Author

Only
mount MissionControl::Jobs::Engine, at: "/jobs"

@rosa
Copy link
Member

rosa commented Dec 30, 2024

This is so strange. The custom I18n configuration is only used here, to set I18n.config, which is thread-safe, so it shouldn't affect a subsequent request at all.

Could you debug your app so that you check the value of I18n.available_locales first on the beginning of a request to / after restarting your server, then on a request to /jobs and then on another request to /?

@kaluznyo
Copy link
Author

I try to make a new rails 8 project on https://github.com/kaluznyo/test_mc_i18n, the only modification is :

  • Add a dummy controller with a show method. It use <%= t('.test') %>
  • Add a fr.yml and config.i18n.default_locale = :fr on application.rb
  • Add Mission Control

I reproduce with the same way. Launche server, open directly /jobs, then /dummy -> Crash. Inverse work well.

@kaluznyo
Copy link
Author

Yes I agree with you... I don't know where is wrong, the I18n.available_locales seems good on console on crashed page...

@rosa
Copy link
Member

rosa commented Dec 30, 2024

Oh, thank you so much for that reproduction app! I can reproduce with that, so I should be able to debug it. Looking into it...

@kaluznyo
Copy link
Author

To add more incomprehension, if I add p I18n.locale_available?(:fr) in the gem on app/controllers/mission_control/application_controller.rb, line 24 at the beginning on set_current_locale(&block)... I think it's work .....

@rosa
Copy link
Member

rosa commented Dec 30, 2024

@kaluznyo I think I found the problem thanks to your app and reproduction steps. The key is that the request to /jobs needs to happen before any other request 😅 The problem is that available_locales defined in Mission Control's I18n configuration ends up polluting the non-thread safe class variable @@available_locales_set 😅 To make things a bit more confusing, there's yet a 3rd config class being used here, Action View's own I18n config proxy class, that I didn't know.

I have a possible fix ready, will push it tomorrow!

rosa added a commit that referenced this issue Dec 31, 2024
In multi-threaded servers when Mission Control is requested before other
pages in the host app.

Fixes #229
@rosa
Copy link
Member

rosa commented Dec 31, 2024

@kaluznyo, I've prepared a fix in #231, could you confirm whether it fixes the bug for you?

@kaluznyo
Copy link
Author

Works fine ! Thanks !

@rosa rosa closed this as completed in #231 Jan 2, 2025
rosa added a commit that referenced this issue Jan 2, 2025
In multi-threaded servers when Mission Control is requested before other
pages in the host app.

Fixes #229
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 a pull request may close this issue.

2 participants