fix(pglite): use normalized channel name in LISTEN/UNLISTEN - #1093
Open
dikshit-n wants to merge 1 commit into
Open
fix(pglite): use normalized channel name in LISTEN/UNLISTEN#1093dikshit-n wants to merge 1 commit into
dikshit-n wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 firespg_notify('TinyBase', 'hello'), the callback never fires. This is because listen() stored the listener under the normalized key'tinybase'but executedLISTEN TinyBase(with original case). The notification arrived with channel'TinyBase', which did not match the stored key.See: Closes #642
Solution
toPostgresName()) in theLISTENSQL command so PostgreSQL receives the correct case-normalized identifier.UNLISTENcommand.pg.listen('TinyBase')+pg_notify('TinyBase')andpg.listen('TinyBase')+NOTIFY TinyBasework correctly.Changes Made
pgChannelin LISTEN/UNLISTEN SQL, fix unsubscribe function, add case-insensitive notification lookup fallbackTesting
pg.listen('TinyBase', cb)receivespg_notify('TinyBase', 'hello-tinybase')Checklist