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

Unhandled 'error' event #174

Closed
bharatiprashant opened this issue Jun 16, 2021 · 4 comments
Closed

Unhandled 'error' event #174

bharatiprashant opened this issue Jun 16, 2021 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@bharatiprashant
Copy link

bharatiprashant commented Jun 16, 2021

I am using this library to stream data from the database however after running for a while it gives me the following error

throw er; // Unhandled 'error' event ^ Error: Connection terminated unexpectedly at Connection.<anonymous> (/var/app/current/node_modules/pg/lib/client.js:132:73) at Object.onceWrapper (events.js:482:28) at Connection.emit (events.js:376:20) at Connection.emit (domain.js:470:12) TLSSocket.<anonymous> (/var/app/current/node_modules/pg/lib/connection.js:108:12)

till now I suppose it was the issue of pg npm but I am not using that in my project. how to handle the error or any solution to take care of this error would be helpful. Please reply as soon as you can
version - ^4.0.0

@ForbesLindesay
Copy link
Owner

The streaming APIs are very difficult to test. If you can produce a test case showing a problem where I just need a Postgres docker container and a JavaScript file to run, I am happy to look into fixing issues.

@ForbesLindesay ForbesLindesay added the help wanted Extra attention is needed label Jul 6, 2021
@bharatiprashant
Copy link
Author

bharatiprashant commented Jul 7, 2021

Hi @ForbesLindesay, the problem exists from the DB side my DB cannot take a load and it terminates the connection. it there any way to retry the connection.
For the test case, I need to have millions of data on my table and do a CPU intensive task

also is this the right way to handle the error

const db = createConnectionPool({
  bigIntMode: "bigint",
  user: app.db_user,
  host: app.db_host_reader,
  database: app.db_name,
  password: app.db_password,
  port: app.db_port,
  keepAlive: true,
  poolSize: 5,
  idleTimeoutMilliseconds: 0,
  connectionTimeoutMilliseconds: 0,
  onError(err) {
    console.log(err);
  },
});

@ForbesLindesay
Copy link
Owner

That onError is only for errors in connections that are in the pool. To handle errors during the stream, you would need to attach an error handler to the node.js stream using .on('error', err => console.log(err))

@ForbesLindesay
Copy link
Owner

The latest release does fix some errors related to unhandled errors in Postgres connections, so I suspect this may be resolved. If you can still reproduce it, please open a fresh issue with a failing test (it's ok if it's a test that only fails 1% of the time as we can just put it in a for (let i = 0; i < 1000; i++) loop)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants