-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
MaxListenersExceededWarning on threads; many redundant fetches of thread root event #3463
Comments
Here's a branch that I started that I think fixes the unnecessary fetch of the thread root: https://github.com/matrix-org/matrix-js-sdk/compare/develop...davidisaaclee:matrix-js-sdk:avoid-unnecessary-fetch-thread-root?expand=1 It's pretty tough to write a test around this code – I started a test a week ago and I forget the state of it. I can pick this back up later but thought I'd post what I have so far. |
https://github.com/matrix-org/matrix-js-sdk/compare/develop...davidisaaclee:matrix-js-sdk:avoid-unnecessary-fetch-thread-root?expand=1 does not fix the
I'm not sure what the solution here is. Are there other similar situations in this library that already have solutions? We could memoize the call to It looks like there's a similar solution used for scrollbacks (actually, a couple of these stored promises in that file): Lines 5537 to 5540 in 9849818
|
I tried reusing ongoing promises for But I still get matrix-js-sdk/src/models/event.ts Lines 1617 to 1619 in 891e2cb
My reading of this code is that: for each event in a thread, that event re-emits thread.addEventListener(ThreadEvent.Update, event => {
this.reEmitter.emit(ThreadEvent.Update, event);
}); ... which obviously leads to many event listeners (as many as there are processed events in the thread). I don't get the design choice to re-emit |
Yes it'd be a breaking change but likely a welcome one |
@davidisaaclee no objections at this time |
I'm giving up on the fixes in #3530 for now, since they are causing other issues: #3530 (comment) – the reported issues are still in the SDK, so I'd love if someone else wanted to try fixing. |
Did #3541 fix this? |
@clokep not fully, there's still redundant fetches happening where the data model is inadequate and asks the server for a re-up |
Using an account that has some threads, I get the following warning around the first sync:
Stack trace
I haven't encountered any user-impacting issues around this,
but it sounds like this could causeIt looks like this is simply a warning and does not prevent listeners from being added: https://github.com/browserify/events/blob/48e3d18659caf72d94d319871106f089bb40002d/events.js#L211 . This is still noise that could mask a real, easily-identifiable memory leak.MatrixEvent
s to fail to emitThread.update
to certain listeners.More importantly, I believe this is caused by a bug in
Thread#fetchRootEvent
where the remote root event is fetched on every call toupdateThreadMetadata
(e.g. when adding an event to the thread, as will be done for each thread event received during a sync):matrix-js-sdk/src/models/thread.ts
Lines 142 to 153 in dfb079a
Note that this code both checks the cache for an event, then seems to indiscriminately fetch the root event from remote. According to the stack trace, this remote fetch is what leads to the redundant event subscriptions. (If I look at the network tab, I can see that there are many calls to
/rooms/{roomId}/event/{eventId}
for the same event, which I think is the thread root.)I can't say for sure that this is the cause, but it at least seems like a bug in itself. If these are not related issues, I'd be happy to split this issue.
If this is a correct diagnostic, you should be able to reproduce the issue using this repo on an account that has a thread with at least 11 replies (11 = EventEmitter max listeners).
The text was updated successfully, but these errors were encountered: