Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres emitted error goes unhandled (when a connection dies) - app crashes #5387

Closed
azigelman opened this issue Jan 21, 2020 · 3 comments
Closed

Comments

@azigelman
Copy link

azigelman commented Jan 21, 2020

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[x] 0.2.22 (or put your version here)

Steps to reproduce or a small repository showing the problem:

Create a connection of type 'Postgres' with pg version > "7.13.0"
Run a query (e.g. select pg_sleep(8))
Terminate the connection unexpectedly (e.g. disconnect from the DB side running the following SQL on your database from a different proccess)

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
where query = 'select pg_sleep(8)';

The app crashes with error:

events.js:200
      throw er; // Unhandled 'error' event
      ^

Error: Connection terminated unexpectedly
    at Connection.<anonymous> (/typeorm_debug/node_modules/pg/lib/client.js:255:9)
    at Object.onceWrapper (events.js:312:28)
    at Connection.emit (events.js:223:5)
    at Socket.<anonymous> (/typeorm_debug/node_modules/pg/lib/connection.js:133:10)
    at Socket.emit (events.js:228:7)
    at endReadableNT (_stream_readable.js:1185:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
Emitted 'error' event on Client instance at:
    at connectedErrorHandler (/typeorm_debug/node_modules/pg/lib/client.js:202:10)
    at Connection.<anonymous> (/typeorm_debug/node_modules/pg/lib/client.js:272:9)
    at Object.onceWrapper (events.js:312:28)
    [... lines matching original stack trace ...]
    at processTicksAndRejections (internal/process/task_queues.js:81:21)

I guess that there is an error being emitted and not being caught.
Can a change in Typeorm prevent this?

Thanks

@smdesmet
Copy link

This error is emitted from the databaseConnection in PostgresQueryRunner.ts. If you install an error event listener on that databaseconnection, the application doesn't crash(the transaction is also not rolled back, so the query failed without typeorm knowing about it...).

@GnanaRaga
Copy link

Could you please elaborate on how to install an error event listener on the databaseconnection

@imnotjames
Copy link
Contributor

Seems to be a Duplicate of #5112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants