-
Notifications
You must be signed in to change notification settings - Fork 0
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
Isolated problem to using Mobility gem and Good Job together #2
Comments
bundle install |
@bensheldon if you can confirm the problem, we might want to invite https://github.com/shioyama to this project? |
The two gems worked together fine in Rails 6.1.4.1 |
Of course the point is also this only occurs in Puma cluster mode (web concurrency) |
👍 I'll take a look later tonight |
Thanks! I added an Issue on Mobility as well: |
Alpha Rails, Puma in cluster mode, A tale of two gems....where to start? haha |
Very very strange... I'll have a look too. |
So it happens even without |
I wonder if this one could be implicated: shioyama/mobility#520 It defines |
Ok, I think the problem is with Mobility's Rails generators. If I comment out this line, the request goes through: require "rails/generators/mobility/generators" if defined?(Rails) This code is not carefully watched and hard to test, so it kind of makes sense that something strange would be missed there. |
Ok, specifically it's this file:
I suspect there are some things that changed in Rails that makes these things fail in some kind of weird way. I need to find a way to test this stuff better... |
Ok crazy thing, it's this line: delegate :connection, to: ::ActiveRecord::Base If I replace that with: def connection
::ActionRecord::Base.connection
end then the problem goes away. Although the two are functionally the same, the difference being that in the current implementation And indeed it seems the problem here is simply referencing |
I think this should fix it: shioyama/mobility#550 It doesn't change anything other than avoids referencing The weird thing though is that the file is only loaded if |
@shioyama thank for digging into this. This matches up with deadlocks I've experienced in the past with GoodJob, and what I've done to fix them:
The intuition that I've been coding against is that static code inside of gems shouldn't reference I've seen this problem manifest in GoodJob quite a bit, but I'm not sure if that's because GoodJob is aggressive with instantiating worker threads and database connections immediately after Rails initialization (and thus race conditions are most visible to GoodJob), or if GoodJob is doing something wrong with Rails Executors/ActiveRecord Connections, or if there is a bug in Rails. I do think it seems surprising and against common practice for gems to be so hands-off ActiveRecord constants. That said, searching the Rails repo for "ActiveRecord deadlock" brings up quite a lot of issues with similar insights, for example: rails/rails#34310 (comment) Lastly, I'm curious how you were able to isolate down the problem so quickly; I am impressed. |
@shioyama Yes I'm also really impressed! But why does this only manifest when the two gems are both installed? 🤔 |
Manual code bisecting:
As far as Mobility is concerned it's just the referencing of I don't know enough about changes in Rails 7 or GoodJob to say more about that side of the picture though. |
p.s. released 1.2.5 with the fix in shioyama/mobility#550. |
Thank you! |
Can you pull, update and run this and see that you also get the problem now?
The text was updated successfully, but these errors were encountered: