Ok, I've refactored the service to not use the connection_pool
, but to use a new connection
instead.
And this also satisfies the rspec tests. I still don't understand what the issue was, but this is a working solution,
and as far as I see it also prevents us from blocking more and more connections, but instead closing them reliably.
This is the new code:
class ExecuteSqlService
class << self
def call(sql) # rubocop:disable Rails/Delegate
new.call(sql)
end
end
def call(sql)
log(sql)
@connection = ActiveRecord::Base.connection
@connection.exec_query(sql)
# was:
# connection.exec_query(sql)
ensure
@connection.close
# was:
# close_connection
end