2

I created a method called connect_and_do_something like below;
What this method does is:
①to connect SampleModel with various databases passed as an argument db_name
②do something by using SampleModel

def connect_and_do_something(db_name)
  config = {
     adapter: XXXX,
        host: XXXX,
    username: XXXX,
    password: XXXX,
     db_name: db_name
  }

  # connect with database dynamically
  SampleModel.establish_connection(config)
 
  ### do something here with SampleModel and DB(MySQL) ####
end

This is working fine in most cases, but sometimes I receive connection pool error when it's requested by a lot of users at the same time (multiple thread).

No connection pool for SampleModel

This is different from ActiveRecord::ConnectionTimeoutError, which appears we cannot obtain connection from connection pool within the time limit.

Now, I'm so confused why this can happen and why this happen occasionally.

Why does this happen occasionally? and How can I resolve it? Thank you in advance.

  • create `pool` key in you config hash an set its value to 3 or 5 if you are not sure what connection pool is. – marmeladze Jun 04 '22 at 15:33

0 Answers0