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

Confusing session lock error message shown if tab re-opened shortly after closing it #26165

Closed
ManuelHu opened this issue Sep 13, 2023 · 13 comments · Fixed by matrix-org/matrix-react-sdk#11800
Labels
O-Occasional Affects or can be seen by some users regularly or most users rarely S-Minor Impairs non-critical functionality or suitable workarounds exist T-Defect

Comments

@ManuelHu
Copy link

Steps to reproduce

  1. being logged in the element web instance
  2. Close the tab
  3. open a new tab with the same element web instance in a time frame shorter than 30s

Outcome

What did you expect?

Element opens again - as with Element 1.11.40 - without any user intervention

What happened instead?

The message "%(brand)s is open in another window. Click "Continue" to use %(brand)s here and disconnect the other window." is shown [%(brand) has bee redacted by me]

Note that at the time, no other instance is running and no tab/window is open, so the message is confusing to users. Apart from that, the re-startup after clicking continue is annoyingly long.


See:
matrix-org/matrix-react-sdk#11425
matrix-org/matrix-react-sdk#11416

Operating system

Windows, Linux

Browser information

Firefox 117, 118

URL for webapp

No response

Application version

Element 1.11.41

Homeserver

Synapse 1.92.1

Will you send logs?

No

@dbkr dbkr added S-Minor Impairs non-critical functionality or suitable workarounds exist O-Occasional Affects or can be seen by some users regularly or most users rarely labels Sep 18, 2023
@richvdh
Copy link
Member

richvdh commented Sep 21, 2023

I wasn't able to reproduce this. Closing the tab should cause the session lock to be dropped so that the new tab opens immediately.

Are you able to provide any more details to help me reproduce the problem?

@ManuelHu
Copy link
Author

Sadly, I do not really have any more insight currently. I have just tested it again on FF 118 (beta) on Linux, and it still reproducible. But this is not a linux-only problem, a user of my element instance could also reproduce it with Firefox on Windows.

My test sequence:

  • open Firefox window
  • open Element tab and another new tab, activate the Element tab
  • Ctrl+W and Ctr+Shift+T in short succession (< 1 second!)
  • (the empty new tab is just that firefox does not close)

I have tried without any adblockers and firefox tracking protection, but the problem still persists.

The problem does not occur every time. Depending on how fast I manage to open the tab again, roughly 50 - 90% of my trials to produce the confusing session lock message "succeed"...


In the browser console I see:

getSessionLock[<new session guid>] Last ping (from <old session guid>) was 11204ms ago, waiting bundle.js:2:3221130
getSessionLock[<new session guid>] Last ping (from <old session guid>) was 30023ms ago: proceeding with startup bundle.js:2:3221130

so the UI is showing correctly and the old lock is still there - So somehow the clearing mechanism does not work reliably?

@richvdh
Copy link
Member

richvdh commented Sep 21, 2023

right yes, I can reproduce that. Thanks.

@richvdh
Copy link
Member

richvdh commented Sep 21, 2023

Hrm, the pagehide event isn't firing.

It's difficult to see this as other than a Firefox bug, and I have opened https://bugzilla.mozilla.org/show_bug.cgi?id=1854492 to track it. However, I fear we'll have to work around it.

I avoided the unload event since apparently it's unreliable and comes with big warnings, but on this basis, the pagehide event is even less reliable. Maybe we should listen to both and drop the lock when either happens...

@ManuelHu
Copy link
Author

I read the linked page, and I cannot find a hint that unload should be less reliable than pagehide - but it additionally disables the bfcache. At least the page only mentions the same scenarios for unload/pagehide (i.e. mobile browsers that cannot observe their own termination).

But of course, the "alternative" visibilitychange event is certainly not an option - Element should be able to work in the background :-)

@ManuelHu
Copy link
Author

I did some quick testing and replaced paghide with unload in the vendor bundle on my Element instance. On firefox this fixes the session lock not being cleared.

@ZanderBrown
Copy link

Instead of using events documented to be unreliable to try detect a tab closing, why not use a BroadcastChannel to simply ask other tabs if they are alive?

Between browser crashes, restarts to update, or even just accidentally hitting reload, I'm hitting this several times a day and it's getting a teensy bit old :-)

@richvdh
Copy link
Member

richvdh commented Oct 23, 2023

Instead of using events documented to be unreliable to try detect a tab closing, why not use a BroadcastChannel to simply ask other tabs if they are alive?

And wait how long for a reply? Too short and we risk starting up while there are two sessions running, corrupting the data store. But any timeout is just even more time waiting for Element to start.

@ManuelHu
Copy link
Author

I'd like to implement the solution outlined by @richvdh above, so to listen to both events, but only run the event handler once. This certainly would have some 'benefits' over the current solution:

  • it works on firefox, as the unload event gets fired reliably (in my tests with a patched Element)
  • the unload event handler also blocks Element from ever getting into the bfcache, which is - as far I understand the comments in the session lock code - never desired
  • If Chrom(e|ium) really is firing pagehide more reliably than unload on Desktop systems (which I highly doubt), Element would still have a handler for it.

I will be preparing a pull request

@richvdh
Copy link
Member

richvdh commented Oct 24, 2023

@ManuelHu that sounds great, thank you!

@ManuelHu
Copy link
Author

@richvdh It just came to my mind that it might be helpful to update the mozilla upstream bug, as now develop.element.io is fixed.
If I remember correctly, there is at least one site providing (all) old element releases online?—but I do not remember what it was called...

@t3chguy
Copy link
Member

t3chguy commented Nov 10, 2023

@richvdh
Copy link
Member

richvdh commented Nov 10, 2023

I have to say I can no longer reproduce this even on older versions such as https://riots.im/1.11.46 :/

gabrc52 added a commit to sipb/matrix-react-sdk that referenced this issue Nov 12, 2023
* Knock on a ask-to-join room if a module wants to join the room when navigating to a room ([\matrix-org#11787](matrix-org#11787)). Contributed by @dhenneke.
* Element-R:  Include crypto info in sentry ([\matrix-org#11798](matrix-org#11798)). Contributed by @florianduros.
* Element-R:  Include crypto info in rageshake ([\matrix-org#11797](matrix-org#11797)). Contributed by @florianduros.
* Element-R: Add current version of the rust-sdk and vodozemac ([\matrix-org#11785](matrix-org#11785)). Contributed by @florianduros.
* Fix unfederated invite dialog ([\matrix-org#9618](matrix-org#9618)). Fixes element-hq/element-meta#1466 and element-hq/element-web#22102. Contributed by @owi92.
* New right panel visual language ([\matrix-org#11664](matrix-org#11664)).
* OIDC: add friendly errors ([\matrix-org#11184](matrix-org#11184)). Fixes element-hq/element-web#25665. Contributed by @kerryarchibald.
* Fix rightpanel hiding scrollbar ([\matrix-org#11831](matrix-org#11831)). Contributed by @kerryarchibald.
* Fix multi-tab session lock on Firefox not being cleared ([\matrix-org#11800](matrix-org#11800)). Fixes element-hq/element-web#26165. Contributed by @ManuelHu.
* Deserialise spoilers back into slash command form ([\matrix-org#11805](matrix-org#11805)). Fixes element-hq/element-web#26344.
* Fix Incorrect message scaling for verification request ([\matrix-org#11793](matrix-org#11793)). Fixes element-hq/element-web#24304. Contributed by @capGoblin.
* Fix: Unable to restore a soft-logged-out session established via SSO ([\matrix-org#11794](matrix-org#11794)). Fixes element-hq/element-web#25957. Contributed by @kerryarchibald.
* Use configurable github issue links more consistently ([\matrix-org#11796](matrix-org#11796)).
* Fix io.element.late_event received_ts vs received_at ([\matrix-org#11789](matrix-org#11789)).
* Make invitation dialog scrollable when infos are too long ([\matrix-org#11753](matrix-org#11753)). Contributed by @nurjinjafar.
* Fix spoiler text-align ([\matrix-org#11790](matrix-org#11790)). Contributed by @ajbura.
* Fix: Right panel keeps showing chat when unmaximizing widget.  ([\matrix-org#11697](matrix-org#11697)). Fixes element-hq/element-web#26265. Contributed by @manancodes.
* Fix margin of invite to room button ([\matrix-org#11780](matrix-org#11780)). Fixes element-hq/element-web#26410.
* Update base64 import ([\matrix-org#11784](matrix-org#11784)).
* Set max size for Element logo in search warning ([\matrix-org#11779](matrix-org#11779)). Fixes element-hq/element-web#26408.
* Fix: emoji size in room header topic, remove obsolete emoji style ([\matrix-org#11757](matrix-org#11757)). Fixes element-hq/element-web#26326. Contributed by @kerryarchibald.
* Fix: Bubble layout design is broken ([\matrix-org#11763](matrix-org#11763)). Fixes element-hq/element-web#25818. Contributed by @manancodes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-Occasional Affects or can be seen by some users regularly or most users rarely S-Minor Impairs non-critical functionality or suitable workarounds exist T-Defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants