-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Live Queries Server: wrong event returned when multiple subscription triggered #7340
Comments
Thanks for reporting! That's a great in-depth examination of the issue, we'll look forward to the PR. To classify the bug severity, are you aware of any workaround to mitigate this issue? |
There is no workaround for all I know... |
Well if all the subscriptions concerned are in the same app, you can create 1 subscription (with a bigger filter) and use the const sub = await Parse.Query("MyCollection").subscribe()
sub.on("update", (object) => {
if (object.get("myBoolean") === true) {
// logic if true
} else {
// logic if false
}
}) But this can lead to a lot of events being sent, and also you'll need to cache locally the previous value of Now if the subscriptions are in different apps I think the only way to bypass this would be to add a "buffer" state for your object, i.e. instead of switching |
If any delay occurs after "message.event" assignation in LiveQueryServer._onAfterSave, the next subscription or request with a different event might overwrite it, and by that using the wrong "push" function name.
Yes, that's true: I've answered too quickly. Those workarounds may work in some specific cases but aren't really sustainable, as explained by @fbeiger. |
Thanks for providing more details. I classify this issue as bug with severity S3 (normal - blocks non-critical functionality and a work around exists):
|
…h event (parse-community#7341) * Add a failing test for issue parse-community#7340 If any delay occurs after "message.event" assignation in LiveQueryServer._onAfterSave, the next subscription or request with a different event might overwrite it, and by that using the wrong "push" function name. * Remove updade of message and use res.event instead This prevent computing function name from a incorrect event if multiple subscriptions override one by one the message.event. * Update CHANGELOG.md * Replace setTimeout by async/await expressions
🎉 This change has been released in version 5.0.0-beta.1 |
🎉 This change has been released in version 5.0.0 |
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 andenter
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 themessage.event = ...
at ParseLiveQueryServer.js#L301.message.event = ...
is an update of the argument and cause issues because it's used in the asynchronousforEach
. When themessage.event
is updated in one of theforEach
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 ofmessage.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
fromtrue
tofalse
(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
andenter
).Actual Outcome
With the example above we received two identical event (e.g.
leave
).Expected Outcome
We expect to receive two opposite events,
leave
andenter
.Failing Test Case / Pull Request
We are working on the PR! It will be created soon 🙂
Environment
Server
4.5.0
Node 12 on Heroku (Ubuntu)
Heroku
Database
MongoDB
4.2.13
MongoDB Atlas
Client
JavaScript
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 themessage.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.
The text was updated successfully, but these errors were encountered: