porsager / porsager/postgres

Crash from unestablished connection

Open
#896 0 comments 0 reactions 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

Getting the following error when it fails to establish connection.

More context:

  • this only happens when i try to run my nodejs server while postgresql db server is off or inaccessible (e.g. due to docker initialization)
  • in docker postgres if you have init sql scripts it will restart once. if your nodejs server tries to connect while it's initializing / restarting, you'll get this error above.
file://server/node_modules/postgres/src/connection.js:389
      stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
                                               ^

TypeError: Cannot read properties of undefined (reading 'replace')
    at queryError (file://server/node_modules/postgres/src/connection.js:389:48)
    at errored (file://server/node_modules/postgres/src/connection.js:384:17)
    at Socket.error (file://server/node_modules/postgres/src/connection.js:376:5)
    at Socket.emit (node:events:519:28)
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.13.1

Similar scenarios here: https://github.com/kysely-org/kysely-postgres-js/issues/60

Thank you thank you <3

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

Start in src/connection.js around queryError at the reported line, then reproduce the failure while the PostgreSQL server is unavailable or restarting. Done means this scenario no longer throws the secondary undefined.replace TypeError and instead reports the connection failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, postgresql
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.