Websocket opening takes ages after repeated failures to same address
Categories
(Core :: Networking: WebSockets, defect, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox122 | --- | fixed |
People
(Reporter: waclaw66, Assigned: acreskey)
References
Details
(Whiteboard: [necko-triaged][necko-priority-queue], [wptsync upstream])
Attachments
(8 files)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0
Steps to reproduce:
I'm having issue with websocket opening on a certain domain that takes long time ~ 40s.
I've created a demo client and server project (attached) to debug it.
Client with javascript is available on:
https://pong.bolesiny.net/
https://pong.waclaw.cz/
Check the console, there is no visible html output.
Actual results:
When Firefox is opened, websocket is opened immediately. After a while (minutes) of browsing on about ~30 tabs it takes a long time to open that websocket in client demo. Once websocket is opened, then its reopening is fast again. After few minutes of inactivity its opening take ages again. The weird thing is that it does only on particular domain bolesiny.net, I've tried another domains (e.g. waclaw.cz) reverse proxied to the same server and it works without any problem. All those domains use the same way generated letsencrypt certificate.
You can check the profile https://share.firefox.dev/3HM8Ps0 of that slow websocket opening, it could help to trace the problem.
I've tried to disable antivirus, didn't help. It works fine with a clear Firefox profile and in Chrome as well. It's dependent to a specific FF state, probably high amount of tabs or websockets on a particular domain.
Expected results:
Websocket should be opened fast on any domain.
| Reporter | ||
Comment 1•3 years ago
|
||
Comment 2•3 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Security: PSM' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
| Reporter | ||
Updated•3 years ago
|
| Reporter | ||
Comment 3•3 years ago
|
||
I think I've found a cause and know how to reproduce it. It's caused by many unsuccessful websocket opening attempts.
One of those mentioned (pinned) tabs is Grafana which uses websocket for live updates. I have unintentionally not enabled websocket upgrade in nginx reverse proxy for its subdomain. Grafana tries to connect to websocket every 15s, after few minutes, connecting to websockets for that domain and all other subdomains take ages (20-100s).
Once I enabled websocket upgrade for that Grafana subdomain, websockets for whole domain started working flawlessly.
Seems to be an issue in Firefox. Does Firefox somehow recycle websockets for a domain or is there any websocket pool limit?
| Reporter | ||
Comment 4•3 years ago
|
||
I have prepared a simpe demo that demostrates the problem...
https://pong.bolesiny.net/proof/
Tried FF 110b9 devel edition and nightly 111a1, the second connection took always >30s in my case. Tested on different machines, always same problem.
Chrome without any problem.
| Reporter | ||
Comment 5•3 years ago
|
||
I've tested FF with mozregression as far as I could (because of old TLS cababilities) and it looks that FF suffers with above problem since the beginning.
Comment 6•3 years ago
|
||
| Reporter | ||
Comment 7•3 years ago
|
||
Hi Sunil, can you filter for "connected" and post all connection times?
Comment 8•3 years ago
|
||
Comment 9•3 years ago
|
||
I was able to reproduce this locally using this link https://pong.bolesiny.net/proof/.
Apart from the huge connection time difference with regard to chrome, I also noticed that Firefox connects only once, whereas Chrome reconnects after few failures.
Updated•3 years ago
|
| Reporter | ||
Comment 10•3 years ago
|
||
Thats weird, I've tested it on three different PC with different internet access, Windows 10, Fedora 37, always the same :/
Althought you are on MacOS, right?
| Reporter | ||
Comment 11•3 years ago
|
||
| Reporter | ||
Comment 12•3 years ago
|
||
Updated•3 years ago
|
Comment 13•3 years ago
|
||
(In reply to Václav Nováček from comment #10)
Thats weird, I've tested it on three different PC with different internet access, Windows 10, Fedora 37, always the same :/
Althought you are on MacOS, right?
Thats correct!
| Reporter | ||
Comment 14•3 years ago
|
||
Comment on attachment 9317445 [details]
ChromeFailingWebSocket
Ohh wait, now I spotted that, you've tested Chrome :D Therefore I was surprised, that's working.
| Reporter | ||
Comment 15•3 years ago
|
||
(In reply to Sunil Mayya from comment #9)
I was able to reproduce this locally using this link https://pong.bolesiny.net/proof/.
Apart from the huge connection time difference with regard to chrome, I also noticed that Firefox connects only once, whereas Chrome reconnects after few failures.
Please check the javascript behing, you've maybe misunderstood that demo example.
There are two kind of connections. First connects every 60s to proper websocket endpoint. The second tries to connect to false websocket endpoint, therefore it fails. That failures of second connection cause that those huge re-connection times of first connection.
Comment 16•3 years ago
|
||
I'll have a look at whether we're implementing the spec correctly.
Updated•3 years ago
|
Updated•3 years ago
|
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Comment 17•2 years ago
|
||
This is interesting; thanks for logging it, Václav.
It looks like we keep track of webSocket connect failures by address and port.
In this test we attempt to connect to two urls, both at the same address and port:
wss://pong.bolesiny.net/ws (valid)
wss://pong.bolesiny.net/ (invalid)
We repeatedly attempt the invalid url which fails and thus progresses the expontential backoff for that address/port.
From RFC 6455 , "clients SHOULD use some form of backoff when trying to reconnect after abnormal closures as described in this section."
But if we keyed the errors by the full url and port -- that seems like it would prevent this seemingly odd behaviour and still minimize reconnects after failure.
Note that the test provided in this bug works gracefully in both Chrome (as noted) and an Safari (i.e. connections to the valid WebSocket URL are not delayed).
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Comment 18•2 years ago
|
||
Hmm, although we key Websocket connections off the address so implementation-wise if we key failures off the full url we've introduced some complexity.
Valentin -- thoughts?
| Assignee | ||
Comment 19•2 years ago
|
||
Although our implementation follows the intention of rfc6455#section-4.1, we can handle the described situation more gracefully by prioritizing new WS connections to paths that have not previously failed.
| Assignee | ||
Comment 20•2 years ago
|
||
We can discuss in the patch, but what's happening is that we need to serialize attempts to connect to a give host / port pair.
https://datatracker.ietf.org/doc/html/rfc6455#section-4.1
And the repeated failed attempts fill up the queue to that host.
So in this implementation I allow WS connections to a path that has not failed yet to get priority in the queue.
| Assignee | ||
Comment 21•2 years ago
|
||
Depends on D193386
Updated•2 years ago
|
Comment 22•2 years ago
|
||
Comment 24•2 years ago
|
||
Backed out for bc failure on browser_staticPartition_websocket.js
Backout link: https://hg.mozilla.org/integration/autoland/rev/cfb634c3e7654129c226c81ad4eedf017f062043
Log link: https://treeherder.mozilla.org/logviewer?job_id=436383045&repo=autoland&lineNumber=12093
Comment 26•2 years ago
|
||
| Assignee | ||
Updated•2 years ago
|
Comment 27•2 years ago
|
||
Backed out for bustages on WebSocketChannel.cpp
Backout link: https://hg.mozilla.org/integration/autoland/rev/f371dd435ba9da0420c0f6b3664afc0673f92bce
Log link: https://treeherder.mozilla.org/logviewer?job_id=437446239&repo=autoland&lineNumber=57888
Comment 29•2 years ago
|
||
Comment 30•2 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/36f007cf29d0
https://hg.mozilla.org/mozilla-central/rev/180501fca227
| Assignee | ||
Updated•2 years ago
|
Description
•