Can't add new command when connection is in closed state
See original GitHub issueIssue type:
[ ] question [x ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] ^0.2.18
(or put your version here)
Steps to reproduce or a small repository showing the problem:
{ QueryFailedError: Can't add new command when connection is in closed state
| at new QueryFailedError (/usr/src/my-app/src/error/QueryFailedError.ts:9:9)
| at Query.onResult (/usr/src/my-app/src/driver/mysql/MysqlQueryRunner.ts:166:37)
| at PoolConnection._addCommandClosedState (/usr/src/my-app/node_modules/mysql2/lib/connection.js:139:11)
| at PoolConnection.query (/usr/src/my-app/node_modules/mysql2/lib/connection.js:534:17)
| at MysqlQueryRunner.<anonymous> (/usr/src/my-app/src/driver/mysql/MysqlQueryRunner.ts:155:36)
| at step (/usr/src/my-app/node_modules/tslib/tslib.js:136:27)
| at Object.next (/usr/src/my-app/node_modules/tslib/tslib.js:117:57)
| at fulfilled (/usr/src/my-app/node_modules/tslib/tslib.js:107:62)
| at process._tickCallback (internal/process/next_tick.js:68:7)
| message: 'Can\'t add new command when connection is in closed state',
| fatal: true,
| name: 'QueryFailedError',
| query: 'COMMIT',
| parameters: [] } }
With no reason, the underlying mysql connection seems to be closed. It seems related to connection pooling (see https://github.com/sidorares/node-mysql2/issues/939)
How can we fix that using typeorm ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top Results From Across the Web
Can't add new command when connection is in closed state
I am using the Amazon EC2 with Ubuntu. I am running the server using the PM2, as pm2 start bin/www --log-date-format "YYYY-MM-DD ...
Read more >Error: Can't add new command when connection is in closed ...
{ Error: Can't add new command when connection is in closed state at PoolConnection._addCommandClosedState. I use mysql 2 and connect Pool.
Read more >Can't add new command when connection is in closed state ...
I had a similar problem and ended up having to put the connection request in it's own .js file and import it into...
Read more >Can't add new command when connection is in closed state
Node+Express+MySQLを使ってデータ取得時に2回目から以下のエラーが発生しましたので、原因と解決…
Read more >Can't add new command when connection is in closed state
Can't add new command when connection is in closed state. ... db.on('error', err => console.error('Keyv connection error:', err));.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In the case you mentioned where you’re using a repository that’s from outside the transaction, yes that would cause issues.
You need to use the @TransactionRepository() in your method instead of your global one in the constructor as the repository likely isn’t bound to a pooled connection once it’s inside the connection manager.
See here: https://github.com/typeorm/typeorm/blob/master/docs/transactions.md#transaction-decorators
@Destreyf No problem, thanks for your help !