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

leaking resources after pool end, pool end should also end all clients of the pool #431

Open
zingmane opened this issue Aug 1, 2023 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@zingmane
Copy link

zingmane commented Aug 1, 2023

I think there is a problem with ending the pool.
When I terminate the pool within a teardown function without explicitly terminating the client, I get a "Leaking resources" error.
When I explicitly end the client, I don't get an error. Same for transactions.

The problem for tests is, that the functions under test should use several connections from the pool. When all test work is done one simply wants to shut down the pool.
In node projects I use https://github.com/brianc/node-postgres and that works as expected, so I think this behavior here is not correct.

Currently my solution is to terminate each client after use, but I don't think that's how it's meant to be used. Furthermore, this does not always work in the case of Transaction.

Can you confirm, this is an error or wrong behavior. If need be I can switch to node-postgres, but I would like to use a deno first lib.

I'm using:

  • Deno 1.34.2
  • deno-postgres 0.17.0

A simple Test is here:

import { afterAll, describe, it } from "https://deno.land/std@0.192.0/testing/bdd.ts";
import { Pool } from "https://deno.land/x/postgres@v0.17.0/mod.ts";
import { assertEquals } from "https://deno.land/x/superdeno@4.8.0/deps.ts";

const dbPool = new Pool(
  {
    user: "myUser",
    database: "myDb",
    port: 5432,
    host_type: "socket",
  },
  1,
  true
);

describe("end pool", () => {
  afterAll(async () => {
    console.log("afterAll");
    await dbPool.end();
  });

  const doQuery = async (query: string) => {
    const client = await dbPool.connect();
    let dbResult;
    try {
      dbResult = await client.queryArray(query);
    } catch (err) {
      console.log(err);
      throw err;
    } finally {
      client.release();
      // client.end();
    }
    return dbResult;
  };

  it("should end all released clients if the db pool is ended", async () => {
    const result = await doQuery("select 1").then((res) => res.rows?.[0]?.[0]);
    assertEquals(result, 1);
  });
});
@bombillazo bombillazo added bug Something isn't working help wanted Extra attention is needed labels Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants