Skip to content

Commit

Permalink
Clear all connection pools active connections
Browse files Browse the repository at this point in the history
We're using gruf v2.20.1, and still experience the deprecation warning
for `clear_active_connections!`.

```
DEPRECATION WARNING: `clear_active_connections!` currently only applies to connection pools in the current role (`reading`).
In Rails 7.2, this method will apply to all known pools, regardless of role. To affect only those connections belonging to a specific role, pass the role name as an argument.
To switch to the new behavior, pass `:all` as the role name. (called from block in call at gruf/lib/gruf/interceptors/active_record/connection_reset.rb:32)>
```

This is caused by rails/rails#45924.

If you're still supporting Rails < 7.1, then we should change this to
use `ActiveRecord::Base.current_role`, but I thought your goal was to
clear any and all active connections -- please correct me if I'm wrong.

Due to Gruf::Controllers::Base rewriting the error message, actually the
backtrace location was confusing.

Maybe `fail!` could be fixed to include it in the message, but that is
beyond the scope of this PR.
  • Loading branch information
zzak committed Nov 21, 2024
1 parent e8947be commit 54331d3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/gruf/interceptors/active_record/connection_reset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConnectionReset < ::Gruf::Interceptors::ServerInterceptor
def call
yield
ensure
target_classes.each { |klass| klass.connection_handler.clear_active_connections! } if enabled?
target_classes.each { |klass| klass.connection_handler.clear_active_connections!(:all) } if enabled?
end

private
Expand Down
2 changes: 1 addition & 1 deletion spec/support/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def active?
end

class ConnectionHandler
def clear_active_connections!
def clear_active_connections!(role)
true
end
end
Expand Down

0 comments on commit 54331d3

Please sign in to comment.