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

Can't add new command when connection is in closed state #2498

Open
Shubh0817 opened this issue Mar 14, 2024 · 0 comments
Open

Can't add new command when connection is in closed state #2498

Shubh0817 opened this issue Mar 14, 2024 · 0 comments

Comments

@Shubh0817
Copy link

I am using mysql2 driver to connect MySql Database with below config

mysql.createPool({
host: process.env.NODE_MYSQL_IP,
user: process.env.MYSQL_USER,
password: decryptPassword(process.env.NODE_MYSQL_PASSWORD),
database: process.env.MYSQL_SCHEMA,
waitForConnections: true,
connectionLimit: 4, // 20 concurrent connections
maxIdle: 4, // max idle connections, the default value is the same as connectionLimit
idleTimeout: 20000, // idle connections timeout, in milliseconds, the default value 60000
queueLimit: 0
});

I am using execute method instead of query.

when i have to just perform select query then i directly use pool but when i have to start transaction then i get connection from pool and then commit and release respectively.

also i have printed free connection with all connection as below code

const allConnections = connection.pool?._allConnections.length ?? connection.connection._pool?._allConnections.length;
const freeConnections = connection.pool?._freeConnections.length ?? connection.connection._pool?._freeConnections.length;

my allConnections become 0 after some time and then i got error as Error: Can't add new command when connection is in closed state on execute method.

please help

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

1 participant