Service continually restarting

molhar
PRO

a year ago

Our core service is continually restarting, typeorm complaining about database connection issues just before it does:
throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();

^

QueryRunnerAlreadyReleasedError: Query runner already released. Cannot run queries anymore.

Seeing this at the same time in the postgres log:
unexpected EOF on client connection with an open transaction

Deployments are also very slow and intermittently seeing a network error for the github branch under service settings in dashboard.

Solved

11 Replies

molhar
PRO

a year ago

Also getting internal network errors on our next.js front end.


a year ago

Can you please share more in depth specific errors.

Is your backend using the private network to connect to the database?


molhar
PRO

a year ago

We are connecting using the private URL.

This error is happening in our medusa app and seems to always be triggered at this point:

app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:173

throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();

^

QueryRunnerAlreadyReleasedError: Query runner already released. Cannot run queries anymore.

at PostgresQueryRunner.query (/app/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:173:19)

at SelectQueryBuilder.loadRawResults (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:2183:43)

at SelectQueryBuilder.getRawMany (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:646:40)

at SelectQueryBuilder.executeEntitiesAndRawResults (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:1989:18)

at SelectQueryBuilder.getRawAndEntities (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:684:40)

at SelectQueryBuilder.getOne (/app/node_modules/typeorm/query-builder/SelectQueryBuilder.js:711:36)

at EntityManager.findOne (/app/node_modules/typeorm/entity-manager/EntityManager.js:596:14)

at Repository.findOne (/app/node_modules/typeorm/repository/Repository.js:239:29)

at ShippingOptionService.<anonymous> (/app/node_modules/@medusajs/medusa/dist/services/shipping-option.js:408:73)

at step (/app/node_modules/@medusajs/medusa/dist/services/shipping-option.js:59:23)

Node.js v20.12.2

I've taken loaded a dump of production data into a local DB and I can't reproduce the error. This only happens with our Railway postgres instance. I've looked at pg_stat_activity and can't see anything out of the ordinary.


molhar
PRO

a year ago

I can see a bunch of queries in postgres stuck in "idle in transaction".

We haven't changed anything that should be altering how transactions are handled recently, this just started today.


a year ago

What node version are you using locally?

What postgres version are you using locally?

What postgres version is running on Railway?


molhar
PRO

a year ago

Local Node: v21.7.1

Local: PostgreSQL 15.3 (Debian 15.3-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit

Railway: Po
stgreSQL 16.0 (Debian 16.0-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit

I can try upgrade my local debian version and see if the same problem occurs?


a year ago

Yeah, try running with Node 20 and Postgres 16 locally.


molhar
PRO

a year ago

Ok I've installed node 20 and postgres 16 and I can't reproduce this locally. I've also tried our staging environment on railway and the same issue occurs.


a year ago

Can you run your app locally and have it connect to the database on Railway?


molhar
PRO

a year ago

I connected my local env to the railway database and triggered the bug.

After much digging it turns out I had an async call missing an await triggering a race condition that only showed up when there was some network latency.

Thanks for your help @brody.


a year ago

Awsome, glad you could solve!


Status changed to Solved brody 11 months ago


Service continually restarting - Railway Help Station