Skip to content

fix(pglite): use normalized channel name in LISTEN/UNLISTEN - #1093

Open
dikshit-n wants to merge 1 commit into
electric-sql:mainfrom
dikshit-n:fix/listen-channel-case-sensitivity
Open

fix(pglite): use normalized channel name in LISTEN/UNLISTEN#1093
dikshit-n wants to merge 1 commit into
electric-sql:mainfrom
dikshit-n:fix/listen-channel-case-sensitivity

Conversation

@dikshit-n

Copy link
Copy Markdown

Summary

Fix pg.listen() not receiving notifications from pg_notify() when the channel name has mixed case (e.g., 'TinyBase').

Problem

When a user calls pg.listen('TinyBase', callback) and a PostgreSQL trigger fires pg_notify('TinyBase', 'hello'), the callback never fires. This is because listen() stored the listener under the normalized key 'tinybase' but executed LISTEN TinyBase (with original case). The notification arrived with channel 'TinyBase', which did not match the stored key.

See: Closes #642

Solution

  1. listen(): Use the normalized channel name (via toPostgresName()) in the LISTEN SQL command so PostgreSQL receives the correct case-normalized identifier.
  2. unlisten(): Same fix for the UNLISTEN command.
  3. Unsubscribe function: Fixed a pre-existing bug where the normalized channel key was incorrectly passed as the callback argument.
  4. Notification lookup: Added a case-insensitive fallback so that both pg.listen('TinyBase') + pg_notify('TinyBase') and pg.listen('TinyBase') + NOTIFY TinyBase work correctly.

Changes Made

  • packages/pglite/src/pglite.ts: Use pgChannel in LISTEN/UNLISTEN SQL, fix unsubscribe function, add case-insensitive notification lookup fallback
  • packages/pglite/tests/notify.test.ts: Add TinyBase regression test for mixed-case pg_notify channel matching

Testing

  • Added regression test: pg.listen('TinyBase', cb) receives pg_notify('TinyBase', 'hello-tinybase')
  • All existing notify API tests continue to pass
  • ESLint: 0 errors (only pre-existing any-type warnings)
  • Prettier: passes
  • TypeScript: compiles cleanly

Checklist

  • Tests pass locally (requires WASM build — CI will verify)
  • Lint passes
  • Code follows repo style
  • No console.log or debug code left
  • No unrelated changes

Fixes pg.listen() not receiving notifications from pg_notify() when
channel name has mixed case (e.g., 'TinyBase').

listen(): use toPostgresName(channel) in LISTEN SQL command.
unlisten(): use toPostgresName(channel) in UNLISTEN SQL command.
Fix unsubscribe function: was passing normalized key as callback.
Add case-insensitive fallback in notification lookup.

Closes electric-sql#642
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS can only listen to lower-case event channels

1 participant