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

Connection failure leaks an open socket #2907

Open
lbguilherme opened this issue Feb 4, 2023 · 0 comments · May be fixed by #2908
Open

Connection failure leaks an open socket #2907

lbguilherme opened this issue Feb 4, 2023 · 0 comments · May be fixed by #2908

Comments

@lbguilherme
Copy link

lbguilherme commented Feb 4, 2023

When trying to connect to a Postgres instance with SSL enabled, but the server didn't enable SSL, we get a "The server does not support SSL connections" as expected. But it does not close the underlying socket and it is leaked, preventing the node process from closing. It will hang for a few seconds/milliseconds until the next GC cycle runs to collect and close the socket.

import pg from "pg";

const client = new pg.Pool({
  connectionString: process.env.CONNECTION_STRING,
  ssl: { rejectUnauthorized: false },
});

try {
  await client.connect();
} catch (e) {
  console.log(e);
} finally {
  await client.end();
}

console.log("done");

This snippet should run and exit immediatelly after showing "done" on the console.

This issue relates to #2720. There are situations where we don't know ahead of time if the database supports SSL or not, and we must try connecting with and without ssl. This is an issue for short-lived applications, such as a migration runner.

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

Successfully merging a pull request may close this issue.

1 participant