porsager / porsager/postgres

CONNECTION_CLOSED on subscribe()

Open
#757 8 comments 3 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

I use standard

const { unsubscribe: _unsubscribe } = await sql.subscribe(
  "*",
  (row, info) => {
    console.log("SUB", row, info)
  },
  () => {
    console.log("SUB!")
  },
)

and it works well.

When postgres goes down I immediately get

Unexpected error during logical streaming - reconnecting Error: write CONNECTION_CLOSED ...
    at closed (https://deno.land/x/postgresjs@v3.4.2/src/connection.js:443:57)
    at https://deno.land/x/postgresjs@v3.4.2/polyfills.js:138:30
    at Array.forEach (<anonymous>)
    at call (https://deno.land/x/postgresjs@v3.4.2/polyfills.js:138:16)
    at closed (https://deno.land/x/postgresjs@v3.4.2/polyfills.js:127:5)
    at success (https://deno.land/x/postgresjs@v3.4.2/polyfills.js:109:7)
    at eventLoopTick (ext:core/01_core.js:189:11) {
  code: "CONNECTION_CLOSED",
  errno: "CONNECTION_CLOSED",

When postgres goes up then I get everything working except for the above subscription -- it never reconnects.

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

Read src/connection.js around line 443 and polyfills.js around lines 109-138, then trace the sql.subscribe logical streaming reconnect path. Reproduce the issue by stopping and restarting PostgreSQL; done means the existing subscription resumes after recovery without the CONNECTION_CLOSED failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
deno, javascript, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.