-
Notifications
You must be signed in to change notification settings - Fork 505
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
Rails 5.2 clear_active_connections!: undefined method `delete' for nil:NilClass #519
Comments
Similar issue: Error on shard master: undefined method `clear' for nil:NilClass
NoMethodError(undefined method `any?' for nil:NilClass):
activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:423:in `block in connected?'
ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:423:in `connected?'
ar-octopus-0.10.2/lib/octopus/proxy.rb:73:in `safe_connection'
ar-octopus-0.10.2/lib/octopus/proxy.rb:80:in `select_connection'
ar-octopus-0.10.2/lib/octopus/proxy.rb:25:in `schema_cache'
activerecord-5.2.3/lib/active_record/model_schema.rb:466:in `load_schema!'
activerecord-5.2.3/lib/active_record/attributes.rb:234:in `load_schema!'
activerecord-5.2.3/lib/active_record/attribute_decorators.rb:51:in `load_schema!'
activerecord-5.2.3/lib/active_record/model_schema.rb:459:in `block in load_schema'
ruby-2.6.2/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize' |
When it happens, the following variables are set to @connections = nil
@thread_cached_conns = nil instead of: @connections=[...]
@thread_cached_conns=#<Concurrent::Map:... entries=0 default_proc=nil>, It means that when Octopus tries to |
How about: def with_each_healthy_shard
shards.each do |shard_name, v|
next if v.instance_variable_get(:@thread_cached_conns).nil?
begin
yield(v) ? |
Running into similar issues, did someone figured out a patch/fork? |
I'm curious if this: rails/rails#36473 improves the situation. I didn't have a chance to test it though. |
I've just hit this issue after upgrading someone to Rails 5.2:
Did anyone have any luck with the patch? Did that ever get added backported to 5.2? edit Unfortunately rails/rails#36473 is included in Rails 5.2 where we are seeing the issue so it doens't look like it helps here. |
Also:
undefined method 'any?'
,'clear'
or'select'
fornil:NilClass
UPDATE: It looks like Octopus is trying to call
clear_all_connections
andclear_active_connections
when connections are alreadydiscarded
.When
with_each_healthy_shard(&:disconnect!)
is executedd, the@connections
and@thread_cached_conns
are alreadynil
(set bydiscard!
method on ConnectionPool class).Background of the story:
I noticed that background jobs (custom made solution using AMQP and Beetle gem, not ActiveJob) occasionally log error message
Error on shard master: undefined method 'delete' for nil:NilClass
, even though they run on shardslave
.Backtrace:
This error message comes from lines (~ 242):
in
Octopus::Proxy
, and the code above seems to be used in methods that clear connections or query_cache.There are 2 issues with this code:
deleting
something, like a connection ;) , but having a backtrace here would help a lot since we're rescuing the error.To address 1., perhaps we could add something like (not a production code):
To address 2.:
The text was updated successfully, but these errors were encountered: