Skip to content

Incorrect handling of real-time events between updates from different tables #462

Open
@matiasbattocchia

Description

@matiasbattocchia

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When subscribing to postgres_changes using the Supabase real-time API, if two tables (conversations and messages) receive simultaneous changes (within milliseconds of each other), the event payloads are incorrectly merged. Specifically, a change from the messages table can appear in the callback for the conversations table.

Code Example:

const channel = supabase
  .channel("rialtaim")
  .on(
    "postgres_changes",
    {
      event: "*",
      schema: "public",
      table: "conversations",
      filter,
    },
    (payload) => {
      console.log("CONVO", payload);
    },
  )
  .on(
    "postgres_changes",
    {
      event: "*",
      schema: "public",
      table: "messages",
      filter,
    },
    (payload) => {
      console.log("MESSAGE", payload);
    },
  );

When simultaneous changes occur, the conversations callback logs a payload from the messages table in addition to the correct conversations payload.

Example output:

CONVO 
Object { schema: "public", table: "conversations", commit_timestamp: "2025-01-16T02:23:03.270Z", eventType: "UPDATE", new: {…}, old: {…}, errors: null }

CONVO 
Object { schema: "public", table: "messages", commit_timestamp: "2025-01-16T02:23:03.271Z", eventType: "INSERT", new: {…}, old: {}, errors: null }

MESSAGE 
Object { schema: "public", table: "messages", commit_timestamp: "2025-01-16T02:23:03.271Z", eventType: "INSERT", new: {…}, old: {}, errors: null }

To Reproduce

  1. Set up real-time subscriptions to two tables using the code above.
  2. Trigger changes in both tables within a very short time interval (milliseconds).
  3. Observe the first callback (conversations) receiving payloads intended for the second subscription (messages).

Expected behavior

Each event callback should only receive payloads for the subscribed table. For example:

  • The conversations callback should receive events only for the conversations table.
  • The messages callback should receive events only for the messages table.

System information

  • OS: Linux
  • Browser: Firefox
  • Version of supabase-js: 2.42.5, 2.47.14
  • Version of Node.js: 21.7.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions