Skip to content

Live Queries Server: wrong event returned when multiple subscription triggered #7340

Closed
@percypyan

Description

@percypyan

New Issue Checklist

Issue Description

Since #7097, when two subscriptions on a collection are triggered simultaneously by a change but with different events (e.g. leave for the first and enter for the second), the same event is returned to the two web socket clients.
This is because of the combinaison of the forEach at ParseLiveQueryServer.js#L240 and the message.event = ... at ParseLiveQueryServer.js#L301.

message.event = ... is an update of the argument and cause issues because it's used in the asynchronous forEach. When the message.event is updated in one of the forEach loop run, it is updated for all. So when the function name is computed at ParseLiveQueryServer.js#L338, the last event attributed is used.

We should use res.event instead of message.event: this way we avoid updating a function argument and we ensure that the right event is triggered.

Steps to reproduce

Create a client with 2 subscriptions on the same collection:

  1. const sub1 = await Parse.Query("MyCollection").equalTo("myBoolean", true).subscribe()
  2. const sub2 = await Parse.Query("MyCollection").equalTo("myBoolean", false).subscribe()

Change an object by updating field myBoolean from true to false (or in the other way).

You'll see that on the client you will receive two identical events (e.g. leave) instead of two opposite event (leave and enter).

Actual Outcome

With the example above we received two identical event (e.g. leave).

Expected Outcome

We expect to receive two opposite events, leave and enter.

Failing Test Case / Pull Request

We are working on the PR! It will be created soon 🙂

Environment

Server

  • Parse Server version: 4.5.0
  • Operating system: Node 12 on Heroku (Ubuntu)
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Heroku

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 4.2.13
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): MongoDB Atlas

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): JavaScript
  • SDK version: 2.10.0

Logs

Logging doesn't work well on our local or Heroku machines. We get %s instead of the actual value.
But we logged the event computed res.event and the message.event and seen the difference. You'll see the details of the bug with the coming PR.

Contributors

Discovered by @fbeiger and @percypyan from PINPODEV.

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:releasedReleased as stable versionstate:released-betaReleased as beta versiontype:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions