Skip to content

fix(live): resolve variable shadowing in unsubscribe callback filtering - #1051

Merged
tdrz merged 1 commit into
electric-sql:mainfrom
Nyx-abu:fix-live-unsubscribe-shadowing
Jul 28, 2026
Merged

fix(live): resolve variable shadowing in unsubscribe callback filtering#1051
tdrz merged 1 commit into
electric-sql:mainfrom
Nyx-abu:fix-live-unsubscribe-shadowing

Conversation

@Nyx-abu

@Nyx-abu Nyx-abu commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Hi team,

I found a bug in the live query unsubscribe logic where trying to remove a specific listener actually drops all subscribed callbacks.

The Bug

In packages/pglite/src/live/index.ts, the inner variable in the ilter function shadows the outer callback parameter:
ypescript callbacks = callbacks.filter((callback) => callback !== callback)
Because of the shadowing, it checks if the callback is not equal to itself, which always evaluates to alse. As a result, the ilter() returns an empty array, and all live query listeners are wiped out whenever a single unsubscription occurs.

The Fix

I simply renamed the inner variable to cb in the three places this occurs:
ypescript callbacks = callbacks.filter((cb) => cb !== callback)

This ensures the filter correctly identifies and removes only the intended listener while preserving the others. Let me know if you need any adjustments!

The inner filter parameter 'callback' shadowed the outer 'callback' argument in the unsubscribe functions. This caused 'callback !== callback' to always evaluate to false, meaning all callbacks were inadvertently unsubscribed when attempting to remove a single listener. Changing the inner parameter to 'cb' correctly preserves the other active listeners.

@tdrz tdrz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thank you!

@tdrz
tdrz merged commit 8b33b92 into electric-sql:main Jul 28, 2026
14 checks passed
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.

2 participants