Skip to content

Pool connections are not gracefully closed once idle connection cleanup occurs. #3148

Open
@dtimofeev

Description

@dtimofeev

Hi,
When Pool._removeIdleTimeoutConnections() is executed and an idle connection is selected for removal (regardless of the conditions) the following code is executed:
https://github.com/sidorares/node-mysql2/blob/master/lib/pool.js#L208
This in turn removes the connection from the pool and directly (non-gracefully) closes it by calling PoolConnection.destroy() instead of PoolConnection.end().
https://github.com/sidorares/node-mysql2/blob/master/lib/pool_connection.js#L50
As a result the connection is closed without notifying the server in any way.

Because of the above the SQL(MariaDB) server is flooded with warnings like:
Aborted connection 123 to db: 'dbname' user: 'dbuser' host: '127.0.0.1' (Got an error reading communication packets)

A possible solution might be to change the current PoolConnection.end() implementation with:

end() {
    this._removeFromPool();
    super.end();
}

but I'm not sure if this solves the issue correctly.

Looking forward to your thoughts on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions