-
Notifications
You must be signed in to change notification settings - Fork 22k
Closed
Description
This issue is present in both 4.1.x and 4.2, but not 3.2.x.
In development, using an autoloaded middleware that references an autoloaded constant, an app will work until a *.yml file is changed. Then it will bomb saying the middleware has been removed from the module tree.
Repro steps:
rails s
- change config/locales/en.yml
- go to http://localhost:3000
To the best of my knowledge, here's what actually happens:
- Updating the .yml file then reloading the page triggers a clear of all autoloaded constants (via the FileChecker)
- This clears the middleware constant that was autoloaded by virtue of
config.middleware.use
- The middleware file, which is used in the request after the reload, held a reference to a model, which mightn't have been defined yet. So the page reload uses
const_missing
in ActiveSupport::Dependencies to look it up - At this time, the .yml change + page reload had already triggered a clear of the middleware constant. The
const_missing
call thinks it's going to need to look up the model in the nesting context of the .yml file, because that's where it was referenced. But that constant has been cleared, so we get "A copy of [middleware] has been removed from the module tree but is still active!" from here.
This problem is solvable by explicitly referencing the top-level model as ::ModelName
instead of ModelName
in the middleware. But as it was a bug introduced in 4.0 and could be a significant time sink, I thought I'd bring it up.
I'm happy to take a stab at resolving this, but I don't grok ActiveSupport::Dependencies enough to make a good first pass.