modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.23k stars 297 forks source link

`dev-server-core/WebSocketsManager`: send periodic ping over WebSockets to prevent connection closure for inactivity #2821

Open larabr opened 1 month ago

larabr commented 1 month ago

What I did

  1. Added pinging mechanism over the web sockets to prevent unexpected connection closure after ~60s (with websocket error 1006) when testing on BrowserStack (Safari).

I couldn't get to the bottom of what exactly is causing the timeout, but sending periodic ping messages fixes it. I checked if the ws server is closing the connection, but it doesn't seem to be the case; using a ping to keep the connection alive is suggested here.

changeset-bot[bot] commented 1 month ago

⚠️ No Changeset found

Latest commit: c4e2bd094a5a1df86e2ec699ad92ea90981512a8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

bashmish commented 1 month ago

Tricky one, I would love to have a stable solution for BrowserStack, many times my tests just randomly failed with timeouts in Firefox and Safari on BrowserStack.

However do you think it's a generic issue with WS or is it due to BrowserStack? If the latter, it would be better to implement this in the BrowserStack adapter

larabr commented 1 month ago

In this case I think it might be due to the Browserstack testing setup, because I couldn't repro with Playwright in local, but I'm not sure if it's a problem unique to the platform: based on other issues I've found around (incl. the one I linked), other network setups might be affected as well.

Edit: the Browserstack support team shared that they use mitmproxy to enable network logs on their side, so the inactivity timeout might come from there.