Missing Websocket pings from backend
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- audio-video-rtc, backend
Research direction
Start with lib/extension/frontend.ts, the WebSocket server entry point named in the issue, and inspect how it creates and manages client connections. Check the server's WebSocket library for ping and pong handling, then reproduce the idle disconnect through the stated HAOS proxy setup. Done when the connection stays alive beyond the 40-second idle timeout and clients that stop responding are cleaned up.
Written by the indexing model from the issue text.
Description
What happened?
Hi,
I use Zigbee2MQTT from within HAOS. HAOS runs its own proxy mechanism for its apps, like this one. And it kills an open WebSocket connection after 40s if there was no data flowing in that time. If you open Zigbee2MQTT from the sidebar and you just wait a while you usually get a message popping up in the bottom right corner telling you "Websocket reconnecting...":
To comply with the RFC 6455 WebSocket specification, the server must initiate the connection heartbeat using standard PING control frames. As browsers are restricted from sending them via the standard JavaScript API, this can not be fixed in the frontend.
So I suggest to implement a proper ping mechanism like this, which ensures that strict reverse proxies like HA Ingress won't drop the connection due to their 40-second idle timeout:
// Set client to status `isAlive`
this.wss.on('connection', (ws) => {
ws.isAlive = true;
ws.on('pong', () => { ws.isAlive = true; });
});
// Ping every 20-30 s
const interval = setInterval(() => {
this.wss.clients.forEach((ws) => {
if (ws.isAlive === false) return ws.terminate();
ws.isAlive = false;
ws.ping();
});
}, 30000);
The relevant file should be this one: https://github.com/Koenkk/zigbee2mqtt/blob/master/lib/extension/frontend.ts
What did you expect to happen?
No response
How to reproduce it (minimal and precise)
- Install HAOS and configure the internal SSL proxy.
- Install the Zigbee2MQTT app.
- Open Zigbee2MQTT from the sidebar.
- Wait.
Zigbee2MQTT version
2.14.2
Adapter firmware version
7.4.5 [GA]
Adapter
SONOFF Zigbee/Thread PoE Dongle Max (Dongle-M)
Setup
I run it as a HAOS app on a Raspberry Pi 5.
Device database.db entry
No response
Debug log
No response
Notes
No response
- Dominant language
- TypeScript
- Stars
- 15.8k
- Forks
- 2k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 43
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Koenkk/zigbee2mqtt
-
problem
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Koenkk/zigbee2mqtt#33516 ·
Maintainers usually reply within 1 day
-
external converter
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Koenkk/zigbee2mqtt#33499 · 3 comments ·
Maintainers usually reply within 1 day
-
new device support
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
Koenkk/zigbee2mqtt#33485 · 6 comments ·
Maintainers usually reply within 1 day
-
problem
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Koenkk/zigbee2mqtt#33467 ·
Maintainers usually reply within 1 day
-
Home Assistant extension republishes a stray `<device>/type {"light": …}` for every device with a `light_type` selectMay be free again @cestercian claimed this 8 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Koenkk/zigbee2mqtt#33464 · 1 comment ·
Maintainers usually reply within 1 day
All issues in Koenkk/zigbee2mqtt
Similar issues
-
Replace discontinued crypto-js in the themePossibly taken @aelmanaa claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
PaloAltoNetworks/docusaurus-openapi-docs#1689 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
solana-foundation/solana-web3.js#4015 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 1/5 1-3 hours Newbie friendliness 90/100
ivopogace/opencode-courier#422 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
chapel-lang/chapel-vscode#158 ·
Maintainers usually reply within 1 day