porsager / porsager/postgres

BUG: If a query fails, it never ends

Open
#1,130 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

I have this code:

try {
    await pg.unsafe("My query");
} catch (e) {
    // whatever
}

The connection is inmediately lost as a test that I have is to close the server socket just when the query starts, so I'm receiving an Error: read ECONNRESET in the catch.

But when I try to end the connection, it lasts forever:

await pg.end();

I went into the code and what I found is that a connection has a rejected query associated, so it just waits for it to finish, but it is already finished, so it waits forever:

Image

Obviously I don't want to add a timeout to the end callback as a workaround. All resources should be cleaned properly.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace the pg.unsafe failure path into pg.end and connection cleanup, using the ECONNRESET reproduction described in the issue. Done means a failed query does not leave shutdown waiting forever and pg.end completes without a timeout workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, postgresql
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.