element-hq / element-web

A glossy Matrix collaboration client for the web.
https://element.io
GNU Affero General Public License v3.0
11.19k stars 2k forks source link

JS networking blocked on FF after Riot has been in a background tab for a while #7858

Open zzottel opened 5 years ago

zzottel commented 5 years ago

After using Riot Web in Firefox (63.0.3 now, but also in earlier versions) over a longer time (several hours), often switching rooms etc., Riot becomes slower and slower.

It often hangs, e.g. while loading room members or avatars, for half a minute or a minute, and then suddenly everything is populated very quickly.

It's not Synapse, though, Riot Android used at the same time doesn't show the same slowness, and after an FF restart, Riot Web is much faster again.

I thought this was #7105, but while it has become quite a bit better since that bug has been fixed, the behaviour is still there. When #7105 was still unfixed, the complete FF would become unusable after some time, and quite quickly. Now, the rest of FF is often (not always) usable without problems. EDIT: Not sure if this is true, maybe I only restart FF earlier than before, see the first comment below.

After some time of growing slowness, Riot states that it has lost the connection to the homeserver (while Synapse is in truth running happily). At this point, switching to another tab using an FF extension (Tree Style Tab) often only works after half a minute or so (but switching tabs using the tabs on top still works). Reloading or Shift-Reloading the Riot tab doesn't work, only goes into loading state without changing the tab contents or replaces the tab contents with white only, but doesn't load anything.

A restart of Firefox fixes that, though after switching to the Riot tab, almost always "Missing Translation"s are shown, see #7847, until I reload the tab. After that Riot Web is snappy again for a while.

While watching Synapse logs and network console in FF, it seemed to me that there might be requests to Synapse that are only answered after a very long time or even never, but Riot Web won't close those, and will only use a certain number of concurrent requests to Synapse. As the number of never-answered requests grows, the number of connections used for actual work goes down, until Riot Web can't even sync anymore.

I'm not at all sure if I interpreted that correctly, though; might be something else entirely.

zzottel commented 5 years ago

Some further notes:

jryans commented 5 years ago

I am sorry to hear you are having this slowdown. I think some more detail about your system configuration may be helpful. Since you're using Firefox, can you go to about:telemetry#environment-data-tab_system and copy the data listed there?

zzottel commented 5 years ago

Eigenschaft Wert memoryMB 15927 virtualMaxMB null cpu.count 4 cpu.cores 2 cpu.vendor GenuineIntel cpu.family 6 cpu.model 94 cpu.stepping 3 cpu.l2cacheKB 256 cpu.l3cacheKB 3072 cpu.speedMHz 3700 cpu.extensions [hasMMX, hasSSE, hasSSE2, hasSSE3, hasSSSE3, hasSSE4_1, hasSSE4_2, hasAVX, hasAVX2, hasAES] os.name Linux os.version 4.19.8-arch1-1-ARCH os.locale de-DE hdd.profile.model null hdd.profile.revision null hdd.binary.model null hdd.binary.revision null hdd.system.model null hdd.system.revision null gfx.D2DEnabled null gfx.DWriteEnabled null gfx.ContentBackend Skia gfx.adapters.[0].description Intel Open Source Technology Center -- Mesa DRI Intel(R) HD Graphics 530 (Skylake GT2) gfx.adapters.[0].vendorID Intel Open Source Technology Center gfx.adapters.[0].deviceID Mesa DRI Intel(R) HD Graphics 530 (Skylake GT2) gfx.adapters.[0].subsysID null gfx.adapters.[0].RAM null gfx.adapters.[0].driver null gfx.adapters.[0].driverVersion 3.0 Mesa 18.2.6 gfx.adapters.[0].driverDate null gfx.adapters.[0].GPUActive true gfx.monitors [] gfx.features.compositor basic gfx.features.gpuProcess.status unused gfx.features.wrQualified.status blocked gfx.features.webrender.status unavailable appleModelId null

zzottel commented 5 years ago

BTW, this did not happen with earlier versions of Riot Web. I think it started with 0.17.0, but I'm not sure.

jryans commented 5 years ago

Do you observe the same behavior in other browsers, or only in Firefox?

zzottel commented 5 years ago

I used it for one and a half days in Chromium (Linux) now and didn't see any problems. There are hangs, sometimes, too, like only spinners for about 10s or more, but I guess that's probably caused by Synapse. Chromium populates the not-yet-loaded items much faster than Firefox afterwards (while I don't see much of a speed difference otherwise), and it doesn't become unusable over time.

That's not a solution for me, unfortunately, as I'm not allowed to install other browsers at work.

sandys commented 5 years ago

is this related to https://github.com/vector-im/riot-web/issues/7801 ?

zzottel commented 5 years ago

More notes:

jryans commented 5 years ago

Thanks for the continued updates! I would certainly like to work out what's causing the poor experience you're seeing.

Are you always running the stable version on riot.im/app?

zzottel commented 5 years ago

I'm running a self-hosted stable version against my own Synapse.

I can't be 100% sure yet, but it seems that deactivating uBlock Origin did the trick (though separate cookie blocking isn't even possible there, I misremembered that). Riot Web worked much longer than normally, I think, until it broke on Matrix HQ and FF told me that this tab was slowing down the browser over and over again each time I told it to wait. This was reproducible every time I looked at Matrix HQ for a few minutes; then I fired up the dev tools to look what was going on, but since then it doesn't happen anymore. X-)

I have uBlock Origin activated again now, but not for the Riot tab. Let's see how it turns out.

jryans commented 5 years ago

I can't be 100% sure yet, but it seems that deactivating uBlock Origin did the trick (though separate cookie blocking isn't even possible there, I misremembered that).

Aha, glad to hear there is a potential theory at least! 😁

it broke on Matrix HQ and FF told me that this tab was slowing down the browser over and over again each time I told it to wait

For this particular bit, you are definitely not alone. Several people mentioned seeing this in both Chrome and Firefox today, but now the room state seems to have changed and resolved the issue for now. Anyway, please do let us know if this variant returns as well.

zzottel commented 5 years ago

Another insight: While investigating 502 errors I saw in the connections tool, I found in the Synapse README that an Apache proxy should have the nocanon option added to the ProxyPass keyword, which wasn't the case at my proxy. This eliminated the 502s, and it seems as if Riot Web now even works with uBlock Origin enabled—at least for a few hours, which is more than I often got before.

Could it be the combination of proxy errors and uBlock Origin that was the problem?

As I'm off for holidays now, I can't test it over the next two weeks to be really sure that helped. I'll get back to you in January.

Happy holidays to you all! :christmas_tree:

zzottel commented 5 years ago

Unfortunately, the measures above didn't fix the problem.

But over the last few days, I analyzed it a bit more, and I can provide more details:

I hope that helps hunting down the problem. I'll change the issue title to better match the actual problem.

zzottel commented 5 years ago

This does not happen anymore.

I'm not sure, though, if it was fixed by Riot Web 1.0.1, Firefox 65.0.1, or by me starting to use workers in my Synapse installation.

My guess is that it's the latter—that it only happened because after switching to the Riot tab, my Synapse was busy sending presence updates to large numbers of other homeservers and thus sometimes didn't answer for minutes. (I think I saw blocked tabs a few days ago again, but it was only for a second or so.)

The question would then be why (and how) Riot Web blocks JS in other FF tabs if network requests aren't answered quickly.

jryans commented 5 years ago

So far, I am not seeing anything here that Riot itself can change to improve the situation. It sounds like it is related more to how Firefox internally schedules work like network activity and JS execution among tabs. Does that sound correct?