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

end() on pg.Client hangs if connect() fails #2777

Closed
MasterOdin opened this issue Jul 29, 2022 · 1 comment
Closed

end() on pg.Client hangs if connect() fails #2777

MasterOdin opened this issue Jul 29, 2022 · 1 comment

Comments

@MasterOdin
Copy link

MasterOdin commented Jul 29, 2022

Given the following code:

const pg = require('pg');
const client = new pg.Client({ host: 'bogushost' });
try {
  await client.connect();
} catch (err) {
  // pass
}
await client.end();

The end() call will hang indefinitely. I've seen this happen with at least ENOTFOUND and ECONNREFUSED errors.

@MasterOdin
Copy link
Author

Slightly different case than #2716, but it ends up the same root cause where the underlying client.connection.stream issues end when the connection fails, and so calling client.end hangs as the end event has already fired. The fix in #2717 fixes this bug as it adds a flag around detecting if the end event was fired. 👍

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

No branches or pull requests

1 participant