porsager / porsager/postgres

Duplicate notifications when subscribing to a publication with postgresjs

Open
#752 2 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

I have created a publication in PostgreSQL and I'm using subscribe to listen to changes. I'm using this code:

const { unsubscribe } = await sql.subscribe(
  'update:users',
  (row, { command, relation, key, old }) => {
    console.log(row, key, old)
  }
)

The problem is that my callback is called twice when I'm updating a record on the users table. Also, I get false for key and null for old in both callbacks. Is there any bug in the implementation or did I do something wrong?

Expected behavior:

I expect the callback to be called only once when I update a record on the users table. I also expect to get the correct values for key and old in the callback.

Actual behavior:

The callback is called twice when I update a record on the users table. I get false for key and null for old in both callbacks.

Environment:

• postgres version: ^3.4.3

• PostgreSQL version: docker image: postgres:15.1

• Node.js version: v18.18.2

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 by reproducing the supplied sql.subscribe example with PostgreSQL 15.1 and the stated Node.js environment, then trace the subscription handling used by postgresjs. Done means an update produces one callback with the correct key and old values, with tests or reproduction evidence covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, postgresql
Domain
backend, databases
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.