Skip to content

random acquire connection timeout and why new connection when freeConnections exist  #2246

Open
@bolin-L

Description

@bolin-L

In my app, I get a few acquire timeout every day, below is code and log

Code is:

  const mysqlPool = app.mysql.pool;

  mysqlPool.on('connection', connection => {
    app.logger.info(`mysql connection and pool detail: ${connection.threadId} - ${mysqlPoolConnection(mysqlPool)}`, { tid: app.tracerTraceId });
  });

  mysqlPool.on('acquire', connection => {
    app.logger.info(`mysql acquire and pool detail: ${connection.threadId} - ${mysqlPoolConnection(mysqlPool)}`, { tid: app.tracerTraceId });
  });

  mysqlPool.on('release', connection => {
    app.logger.info(`mysql release and pool detail: ${connection.threadId} - ${mysqlPoolConnection(mysqlPool)}`, { tid: app.tracerTraceId });
  });

  mysqlPool.on('enqueue', connection => {
    app.logger.info(`mysql enqueue and pool detail: ${connection.threadId} - ${mysqlPoolConnection(mysqlPool)}`, { tid: app.tracerTraceId });
  });

  function mysqlPoolConnection(pool) {
    return `_allConnections: ${pool._allConnections.length}[ ${getConnectionThreadIds(pool._allConnections)} ], _acquiringConnections: ${pool._acquiringConnections.length} [ ${getConnectionThreadIds(pool._acquiringConnections)} ], _freeConnections: ${pool._freeConnections.length} [ ${getConnectionThreadIds(pool._freeConnections)} ]`;
  }

  function getConnectionThreadIds(cons) {
    return cons.map(con => con.threadId).join(',');
  }

And config is

{
        host: 'xxx',
        port: xxx,
        user: 'xxx',
        password: 'xxx',
        database: 'xxx',
        connectionLimit: 10,
        connectTimeout: 3000,
        acquireTimeout: 4000
      }

Here is log:

z13

企业微信截图_3273edb9-905c-46fc-a9e4-24bdf2ac6cd6

企业微信截图_77306c3d-e534-476f-819a-7f4098c5d6ba

企业微信截图_9539248e-8dcb-4725-b890-9aeded2d0951

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions