Reputation: 670
I am using Typeorm with a postgresql database. I am testing a function that runs a findOne query and it throws the following error:
{ QueryFailedError: Connection terminated
at new QueryFailedError (/Users/juanjosegutierrez/projects/banking-server/node_modules/typeorm/error/QueryFailedError.js:27:28)
at Query.callback (/Users/juanjosegutierrez/projects/banking-server/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:212:38)
at Query.Object.<anonymous>.Query.handleError (/Users/juanjosegutierrez/projects/banking-server/node_modules/pg/lib/query.js:142:17)
at process.nextTick (/Users/juanjosegutierrez/projects/banking-server/node_modules/pg/lib/client.js:59:13)
at process._tickCallback (internal/process/next_tick.js:61:11)
message: 'Connection terminated',
name: 'QueryFailedError',
query:
'SELECT "Contact"."id" AS "Contact_id", "Contact"."type" AS "Contact_type" FROM "contacts" "Contact" WHERE "Contact"."id" = $1',
parameters: [ '52e1da6e-f4e1-41dc-9dcd-22679c4265e4' ] }
When I look at my postgres logs I see the following:
LOG: unexpected EOF on client connection with an open transaction
Why am I getting connection terminated?
Upvotes: 7
Views: 8100
Reputation: 670
After stepping through the code, I found that I was missing an async await in one of the parent functions. Because of that, my afterAll block which closes the db connection was being called before my findOne query. The issue was fixed after adding the missing await.
Upvotes: 24