-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat: offline state recovery for Filter subscription #2049
Conversation
ba8867c
to
4c446d5
Compare
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we introduce some tests that validate the diff for this? We can do this by mocking disconnection
a5217ae
to
cf3974d
Compare
}) | ||
); | ||
public isConnected(): boolean { | ||
if (globalThis?.navigator && !globalThis?.navigator?.onLine) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is tricky. I made it that was as to comply with behavior of
const storedPeersData = localStorage.getItem("waku:peers"); |
when if we run localStorage
discovery in nodejs
it won't fail tho it won't work
the thing is even though we don't support nodejs - there are some people running js-waku
in such env
Re your comment of adding tests within the scope of #2078, it'll be great to have the tests strictly for this change of the PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have thoughts about a few things here:
1/
The idea seems to be to watch for the navigator:offline/online event, renew (and resubscribe) to subscriptions. Here, I have a few questions:
- should we instead attempt redials to the peers to confirm if they lost connectivity? - Are we certain the node didn't lose connection to the peer & simply to the Filter subscriptions?
- If it only lost the subscription, should we really
renew
the peer instead of simply resubscribing to the same set of peers? (perhaps check the susbcription status first before renewal?)
2/
Regarding testing the offline
/online
status
even if we consider using a mock for window in test environment AND make it seems like it is offline - it won't be enough as js-waku node won't drop connection to peers so that filter subscription will just continue working;
Maybe I am missing something but I don't see a way to test navigator.onLine changes
We should stub the offline
/online
event emission, along with stubbing relevant peer disconnections. This assumes that the peer indeed lost subscriptions/connections.
3/
This is more of a reminder than it is a suggestion: renewals and resubscriptions also happen regularly at an interval. It's probably better to do it promptly when observability over the online
/offline
status events.
No suggestion here, I think this is indeed a right direction to consider.
Please let me know what you think @weboko
--
Side note: some smaller unrelated diffs seem to be included including change of method names, movement of methods, new internal APIs which is why this is also probably more confusing to me (excuse me if that is the case), would be helpful to make the diff leaner
…nto weboko/fitler-offline
if connectivity is lost then no redials will help as internet is absent, in case it was some application level we could try to redial, I don't see it helping in that case
that's a good point and in this PR instead of renewing right away - we filter.ping peers first and those that fail are renewed.
added test covering this one in connection manager. I don't see any value of covering it in filter as filter already has |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unblocking; please feel free to include whatever you think will be helpful in this PR, rest can be followed up as separate PRs
thank you!
i meant when the application gains connectivity again, perhaps instead of directly renewing and/or resubscribing, redialing the same peer would be beneficial first |
// @ts-expect-error: mocking blobal object | ||
globalThis.navigator = {}; | ||
// @ts-expect-error: mocking global object | ||
globalThis.navigator.onLine = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be better to mock this with Sinon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried wit Sinon originally but then understood that under current structure it is better to properly place eventEmitter
and mocked object. It is due to us not needing to check access (i.e that function was called and how many times) and that due to this test being e2e we want to see how code works when browser API is getting triggered (i.e flow of actions).
Maybe you can share an example? I can follow up with moving it to Sinon
…nto weboko/fitler-offline
Problem
In case light node goes offline some steps should be taken to recover as per RFC recommendation
Solution
Implement recovery by doing
ping
andre-subscription
if needed.Notes