Skip to content
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

is the connection ever released back to the pool if we proxy the query? #1

Open
albertalquisola opened this issue Apr 10, 2018 · 1 comment

Comments

@albertalquisola
Copy link

albertalquisola commented Apr 10, 2018

i hit a max connection limit using this module. is the connection released back to the pool? I looked at the code and it doenst look like it?

how im using it:

const retries = 10;      // How many times will the query be retried when the ER_LOCK_DEADLOCK error occurs
const minMillis = 1000;  // The minimum amount of milliseconds that the system sleeps before retrying
const maxMillis = 10000; // The maximum amount of milliseconds that the system sleeps before retrying
pool.on('connection', (connection) => {
  proxyMysqlDeadlockRetries(connection, retries, minMillis, maxMillis);
});

and when i execute a query

  executeQueryWithParams: (sql, params) => {
    return new Promise((resolve, reject) => {
      pool.getConnection((error, connection) => {
        if (error) {
          log.error('executeQueryWithParams', 'error getting db connection', { error });
          return reject(error);
        }

        connection.query(sql, params, (err, results) => {
          connection.release();
          if (err)
            return reject(err);

          return resolve(results);
        });
      });
    });
  },
@Badestrand
Copy link
Owner

Generally the one calling getConnection is responsible to release it as well. The module never acquires a connection and thus never releases it. It is ignorant to where the connection comes from.

The proxyMysqlDeadlockRetries will eventually call the next function so in your code it should always execute the branch that calls connection.release(). It looks good to me. Have you tried a counter that logs how many times a connection is acquired and released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants