rails: ActionDispatch::Journey::Router NoMethodError (undefined method `names' for nil:NilClass)
When running a multithreaded rails server (JRuby + Puma), occasionally when the rails app starts and several incoming requests hit different routes at the same time, a route might become corrupted and throw this error.
Any subsequent requests to the corrupted route to fail with this error for the lifetime of the application. Only a restart of the application will fix this once it has been corrupted.
Root Cause
- The backtrace points to here which is because match_data is nil
match_data
is nil because theroute.path.match
returns nilroute.path.match
returns nil because the routes@re
instance variable is set incorrectly@re
is lazily evaluated, and in a multi-threaded application this is not safe
Replication
I created an app that replicates this issue here. I apologize for the difficult replication, but since this is a threading related bug it is naturally difficult. I spent several hours trying to get a simple-ish replication, but if we need a better one I can spend some more time on it.
Potential Fix
Here is a potential fix for this issue. I am happy to send a pull request if you want.
Backtrace Attached
Thanks for looking at this issue 😃
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 40 (19 by maintainers)
@qisantanu It’s definitely worth upgrading to the latest jRuby, Rails & puma. I’m using jRuby 9.3.3.0, puma 5.5.2 and Rails 6.1.4 and no problems. Also, I found that using tcp sockets for nginx => puma is much more stable that using unix sockets.
It might be worth trying puma v3.12.x
I’ve been experiencing various strange Rails crashes in puma v4.x on
jRuby
and I filed this bug: https://github.com/puma/puma/issues/2060 . puma v4.x switched tonio4r
for concurrency and thenio4r
developer has confirmed that there are jRuby bugs which aren’t a priority to fix just now. I have switched our project to use puma v3.12.x because that’s been rock solid for a while for us.👍 running into this with jruby 9.0.5.0 and rails 3.2.22 as well