Skip to content
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

fix: guarantee cleanup of stale data on re-subscriptions #15929

Merged

Conversation

prlanzarin
Copy link
Member

@prlanzarin prlanzarin commented Oct 28, 2022

What does this PR do?

  • fix: guarantee cleanup of stale data on re-subscriptions
    • Currently, collection cleanup code is only run when an added event is received from the server. Where that fails is in scenarios where a server-side collection turns empty while an affected users is disconnected - and then reconnects. There's no removed (or updated) event so no cleanup code is run and you have stale data.
    • This commit guarantees a stale data check is run whenever a subscription is established again. The added check was also maintained, although I'm not too sure it's still needed. That may need to be revisited.

Closes Issue(s)

Part of #15829
Part of #15823

Motivation

See #15823 (comment)

Currently, collection cleanup code is only run when an added event
is received from the server. Where that fails is in scenarios where
a server-side collection turns empty while an affected users is
disconnected - and then reconnects. There's no removed (or updated)
event so no cleanup code is run and you have stale data.

This commit guarantees a stale data check is run whenever a subscription
is established again. The `added` check was also maintained, although
I'm not too sure anymore it's is still needed. That may need to be
revisited.
@sonarcloud
Copy link

sonarcloud bot commented Oct 28, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 3 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@prlanzarin
Copy link
Member Author

prlanzarin commented Oct 28, 2022

I tagged this as closing #15829 and #15823 although it's worth nothing: the recorded videos show "inconsistencies" while the client is disconnected, and this just tackles state reconciliation after re-connecting.

Do not expect this PR to fix the fact that while the client is disconnected from the server that does state management (Meteor), you can't "unshare" or "retry" something. If we want to tackle that, we need to properly surface the lack of connectivity to the signaling server (Meteor) to the end user - and explain why they can't do that.
The fact that it just stays in a weird state while disconnected is a side effect of maintaining the local state up even when Meteor disconnects, but doing nothing to surface that fact.

Feel free to remove the Closes tags if fixing state reconciliation is not enough. I just changed the tags to "part of".

@prlanzarin prlanzarin marked this pull request as ready for review October 31, 2022 13:26

self.checkForStaleData();
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a throttle for this function? I think thats good have it, but I think it could add performance issues call it while the client is sync bacause it would generates a lot of calls

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you add a throttle for this function? I think thats good have it, but I think it could add performance issues call it while the client is sync bacause it would generates a lot of calls

I could add a tail debounce, yes. Although I'd like to clear some things up:

  • I don't think it'll "add" performance issues because it's virtually the same as the status quo (v2.5.x/v2.6.x have the same code block as this hooked to the added callback - the only difference here is that I refactored it to a method to be re-usable)
  • From the PR: The added check was also maintained, although I'm not too sure it's still needed. That may need to be revisited. I'm under the impression this doesn't need to be in the added callback anymore if it is run once the subscription is set up. If you can confirm that is the case, I'll just remove it.

Copy link
Member Author

Choose a reason for hiding this comment

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

^ Even though this was merged, It'd be important to verify whether the added cleanup callback is still needed.

@@ -164,6 +167,10 @@ export default withTracker(() => {
},
...subscriptionErrorHandler,
});

Object.values(localCollectionRegistry).forEach(
Copy link
Member

Choose a reason for hiding this comment

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

Also add a throttle here, if it runs as is, it'll generate 961 calls for checkForStaleData

Copy link
Member Author

Choose a reason for hiding this comment

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

If it generates 961 calls, throttling does not seem like the solution - if anything it should be debounced.
Do you have a different place to suggest where this will be called only when absolutely necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also: how did the 961 calls number come up here? Can you provide a reproducible scenario so I can tinker with it?

The way I initially came up with this code is hat this loop would only be run once every subscription handler is ready - so this would amount to the N collection calls to checkForStaleData (which currently is 32).

I just re-validated that adding a call counter stemming from this entrypoint only and it's just that: 32 calls per (re)-connection.

@antobinary antobinary modified the milestones: Release 2.5, Release 2.6 Dec 12, 2022
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.

None yet

4 participants