-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
initialize!
raises FrozenError
when called more than once from an app using zeitwerk
#42319
Comments
initialize!
raises FrozenError
when called more than once from an app using zeitwerk
initialize!
raises FrozenError
when called more than once from an app using zeitwerkinitialize!
raises FrozenError
when called more than once from an app using zeitwerk
@zzak i opened this here because multiple app support is in the api docs - that example will fail if you call that being said, if this is specific to also fwiw my usage case is not hypothetical, it's for testing a rails/rack middleware. if there's another way to do so (or to reset an existing loader instance) without hitting this bug i'd be satisfied but so far all my attempts have failed. |
I just spent some time looking into this afaict there is no way to "reload" once the app is initialized -- but you can create a new app using the same config and that should work. I'm not entirely sure though, so let's wait to see what Xavier says. 🙏 |
if i'm understanding you correctly, i tried that also and it didn't work: require "action_controller/railtie"
class App < Rails::Application; end
class OtherApp < Rails::Application; end
a = App.new.tap(&:initialize!)
# no config, fails
b = OtherApp.new.tap(&:initialize!)
# or with the same config, also fails
b = OtherApp.new(config: a.config).tap(&:initialize!) |
I remember we discussed this in core when doing the integration, and the consensus was that right now we do not support several application instances. @rafaelfranca do you remember? Should we correct that documentation? |
ah, i guess it's ActiveSupport::Testing::Isolation which kept this issue from coming up. |
There was some work in the past to make multiple applications possible, but the place we are right now it is not possible since the work was never finished. Since we have no plans to finish I think we should remove the documentation. |
Fixes rails#42319 Per rails#42319 (comment) this is not meant to be supported.
made a PR to remove the relevant section from the docs: #42961
can you use |
* Run CI against Rails 7 * Add workaround to avoid FrozenError when initializing testing Rails apps See: rails/rails#42319 * Update changelog
ah, a much easier solution was linked. this works for my usage case, thanks @st0012 |
@modosc haha, thanks for creating the issue too. great cooperation I guess 🤝 |
Rails does not support multiple application instances (per process), and, since transitioning to Zeitwerk, calling `initialize!` on additional application instances raises a "FrozenError: can't modify frozen Array" error. (See [rails/rails#42319][] for more information.) This commit makes each `TestFlyRails` and `TestBadEnv` test run in its own process so that there is only one application instance per process. This also prevents the environment variables set in `TestFlyRails#setup` from affecting other (randomly ordered) tests, such as `TestBadEnv#test_middleware_skipped_without_required_env_vars`. [rails/rails#42319]: rails/rails#42319
Steps to reproduce
initialize a rails app twice:
Expected behavior
no errors should be raised - this is the case on
6.0.3.7
and6.1.3.2
with default configsActual behavior
on
main
i get this error:i also found the same behavior when instantiating and initializing instances of two different classes.
a bisect gave me 0d523d8 as the first bad commit which is where
zeitwerk
becomes the default autoloader.i found that in
6.1.3.2
i could get a similar error by enablingzeitwerk
System configuration
Rails version:
b678667
6.1.3.2
6.0.3.7
Ruby version:
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-darwin20]
The text was updated successfully, but these errors were encountered: