-
Notifications
You must be signed in to change notification settings - Fork 173
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
Can't modify frozen Array error when running rspec in Rails 5.1 #534
Comments
I couldn't move bugsnag gem into staging, production groups in Gemfile because this codebase often calls |
Next morning took another stab at it, and found that as this answer suggested, the "frozen array" error was indeed a red herring. Bugsnag just happens to be at the wrong place at the wrong time, since it seems that the first spec error causes the middleware stack to freeze (or something like that), and bugsnag is the first to try inject something after that happens, which then shows up as an error on every other spec. In my case the first error was also very cryptic and seemingly unrelated, which is why I didn't look harder into it. However, perhaps this issue could be more about bugsnag helping stop people from going down this rabbit hole. I'm sure there will be more people updating their Rails and running into stuff like this. They might then see this doc and assume bugsnag is acknowledging this issue. People finding this issue: be sure to listen to this advice and really dig into that first error no matter how unrelated it might appear. |
Glad you got to the bottom of the issue. What would your recommendation be in this case? We could rescue the error that propagates from https://github.com/bugsnag/bugsnag-ruby/blob/master/lib/bugsnag/integrations/railtie.rb#L67 and wrap that exception with a potentially slightly more helpful exception that points people in the right direction? |
I think that could be a welcome addition! 👍 I would also recommend rephrasing the "Custom middleware loading" doc with the following goals:
|
This should never happen in normal operation, but is possible when running RSpec tests See thoughtbot/factory_bot_rails#303 (comment) and #534 Essentially this happens: 1. RSpec boots Rails 2. Rails boot process errors 3. Rails freezes middleware 4. RSpec moves on to the next test file 5. Bugsnag tries to add middleware but fails because it's frozen 6. The stacktrace blames Bugsnag for this test failure 7. goto 4 Supressing this error doesn't solve the problem as it's likely another frozen error will happen in some other library/component, but we want to avoid people thinking this is caused by Bugsnag. The stacktrace does point out the actual problem, but only in the very first error, which can get buried under the frozen errors that happen for each test file
This should never happen in normal operation, but is possible when running RSpec tests See thoughtbot/factory_bot_rails#303 (comment) and #534 Essentially this happens: 1. RSpec boots Rails 2. Rails boot process errors 3. Rails freezes middleware 4. RSpec moves on to the next test file 5. Bugsnag tries to add middleware but fails because it's frozen 6. The stacktrace blames Bugsnag for this test failure 7. goto 4 Supressing this error doesn't solve the problem as it's likely another frozen error will happen in some other library/component, but we want to avoid people thinking this is caused by Bugsnag. The stacktrace does point out the actual problem, but only in the very first error, which can get buried under the frozen errors that happen for each test file
This should never happen in normal operation, but is possible when running RSpec tests See thoughtbot/factory_bot_rails#303 (comment) and #534 Essentially this happens: 1. RSpec boots Rails 2. Rails boot process errors 3. Rails freezes middleware 4. RSpec moves on to the next test file 5. Bugsnag tries to add middleware but fails because it's frozen 6. The stacktrace blames Bugsnag for this test failure 7. goto 4 Supressing this error doesn't solve the problem as it's likely another frozen error will happen in some other library/component, but we want to avoid people thinking this is caused by Bugsnag. The stacktrace does point out the actual problem, but only in the very first error, which can get buried under the frozen errors that happen for each test file
This should never happen in normal operation, but is possible when running RSpec tests See thoughtbot/factory_bot_rails#303 (comment) and #534 Essentially this happens: 1. RSpec boots Rails 2. Rails boot process errors 3. Rails freezes middleware 4. RSpec moves on to the next test file 5. Bugsnag tries to add middleware but fails because it's frozen 6. The stacktrace blames Bugsnag for this test failure 7. goto 4 Supressing this error doesn't solve the problem as it's likely another frozen error will happen in some other library/component, but we want to avoid people thinking this is caused by Bugsnag. The stacktrace does point out the actual problem, but only in the very first error, which can get buried under the frozen errors that happen for each test file
We have added an update in v6.16.0 to improve the behaviour here. |
Description
Trying to run
rspec
after updating rails from 5.0 to 5.1 causes "can't modify frozen Array" error that (upon some research) bugsnag causes when trying to initialize. Seems like it's injecting a middleware after the stack is already frozen.Issue
In a simple rails app I have this config/initializers/bugsnag.rb
After updating Rails from 5.0 => 5.1, trying to run rspec causes this error on every spec.
I read through PRs #419, #444, as well issues #403 and #391, and saw the "doc" for the fix at the bottom of this page, and I'm still unclear what I need to do.
I tried setting
BUGSNAG_DISABLE_AUTOCONFIGURE=true
in my local .env (and moving dotenv gem to the top of Gemfile). I also tried running rspec like this:BUGSNAG_DISABLE_AUTOCONFIGURE=true rspec
. it didn't help.I'm still not sure, and the doc could use a lot of improvement, since it currently seems to be targeting bugsnag developers, and even after quite a number of years doing this, I couldn't understand what it's telling me to do. I'm quoting here:
I don't know what integrations bugsnag provides, up to today bugsnag didn't ask me to configure any integrations. I guess it integrates with rails and sidekiq, is sidekiq a framework?
What does it mean for "framework integrations" to "initialize"? What is "the notifier"? What does it mean for it to be loaded?
Why would I not want "framework integrations to be initialized when notifier is loaded"?
What does it mean to load integration? Am I supposed to put this in initializers? Am I supposed add conditions for "when sidekiq is loading, load sidekiq integration"? Where do I load rails integration? Do I have other integrations I need to be loading? I'm not sure, it's a big app, and I didn't write the entire thing myself. Bugsnag didn't need me to do this before.
Any help much appreciated.
Environment
Library versions:
The text was updated successfully, but these errors were encountered: