Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest version of Parse Server.
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:
const sub1 = await Parse.Query("MyCollection").equalTo("myBoolean", true).subscribe()
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 🙂
- 🤩 I submitted a PR (Fix #7340 by correclty computing function name for push event #7341) with a fix and a test case.
- 🧐 I submitted a PR with a failing test case.
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.