Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typeorm connection terminated

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?

like image 699
jjgg Avatar asked Jul 11 '26 11:07

jjgg


1 Answers

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.

like image 119
jjgg Avatar answered Jul 14 '26 09:07

jjgg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!