nestjs / typeorm

TypeORM module for Nest framework (node.js) 🍇

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Pool is closed when calling appContext.close() in standalone app

krkc opened this issue · comments

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Getting UnhandledPromiseRejectionWarning: Error: Pool is closed. when running as a standalone app. However, if I a) remove the call to appContext.close() (line 69 of gist) or b) add a setTimeout (line 24 of gist) the error goes away. I suspect it has to do with something being garbage collected and closing its connection after appContext.close() has already closed all the connections, and calling setTimeout just reverses that order, but that's just my personal theory.

Full error:
[Nest] 65253 - 09/23/2020, 7:08:24 AM [NestFactory] Starting Nest application... [Nest] 65253 - 09/23/2020, 7:08:24 AM [InstanceLoader] TypeOrmModule dependencies initialized +56ms [Nest] 65253 - 09/23/2020, 7:08:25 AM [InstanceLoader] TypeOrmCoreModule dependencies initialized +447ms [Nest] 65253 - 09/23/2020, 7:08:25 AM [InstanceLoader] TypeOrmModule dependencies initialized +1ms [Nest] 65253 - 09/23/2020, 7:08:25 AM [InstanceLoader] TypeOrmModule dependencies initialized +1ms [Nest] 65253 - 09/23/2020, 7:08:25 AM [InstanceLoader] RolesModule dependencies initialized +1ms [Nest] 65253 - 09/23/2020, 7:08:25 AM [InstanceLoader] UsersModule dependencies initialized +1ms [Nest] 65253 - 09/23/2020, 7:08:25 AM [InstanceLoader] SeederModule dependencies initialized +2ms (node:65253) UnhandledPromiseRejectionWarning: Error: Pool is closed. at /home/christopher/PersonalProjects/tichete-server/node_modules/mysql/lib/Pool.js:149:17 at Array.forEach (<anonymous>) at Pool.releaseConnection (/home/christopher/PersonalProjects/tichete-server/node_modules/mysql/lib/Pool.js:148:37) at Pool._removeConnection (/home/christopher/PersonalProjects/tichete-server/node_modules/mysql/lib/Pool.js:277:8) at Pool._purgeConnection (/home/christopher/PersonalProjects/tichete-server/node_modules/mysql/lib/Pool.js:258:8) at Ping.onOperationComplete (/home/christopher/PersonalProjects/tichete-server/node_modules/mysql/lib/Pool.js:101:12) at Ping.<anonymous> (/home/christopher/PersonalProjects/tichete-server/node_modules/mysql/lib/Connection.js:526:10) at Ping._callback (/home/christopher/PersonalProjects/tichete-server/node_modules/mysql/lib/Connection.js:488:16) at Ping.Sequence.end (/home/christopher/PersonalProjects/tichete-server/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24) at Ping.Sequence.OkPacket (/home/christopher/PersonalProjects/tichete-server/node_modules/mysql/lib/protocol/sequences/Sequence.js:92:8) (node:65253) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:65253) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected behavior

Minimal reproduction of the problem with instructions

minimal gist
I can add another gist with services, entities, configservice, etc if needed...

What is the motivation / use case for changing the behavior?

Environment


Nest version: 7.5.1

 
For Tooling issues:
- Node version: v10.19.0  
- Platform:   Ubuntu 20.04.1 LTS

Others:

Using the mysql node driver.
Running with: `npx ts-node -r tsconfig-paths/register src/all-in-one.ts`

I would suggest reporting this issue in the typeorm repository instead. In fact, close() evaluates the connection.close() under the hood and doesn't perform any additional operations