Skip to content

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

Open
@zingmane

Description

@zingmane

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);
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions