Koenkk / Koenkk/zigbee2mqtt

Crash on start when network connection can't be established

Open
#33,088 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

problem
Dominant language
TypeScript
Stars
15.7k
Forks
2k
Avg merge
18h 55m
Merged PRs (30d)
35

Description

What happened?

Every once in a while my slab-06p7 stops responding for a few seconds.
zigbee2mqtt stops, with a " Socket error Error: read ETIMEDOUT" ; which the Home Assistant watch dog does react to by restarting zigbee2mqtt, however after that you get a node.js crash due to unhandled error.

This prevents the HA watchdog to kick in again.

version 2.14.1-1
logs:

[2026-09-10 03:13:06] info: 	z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/hallway_1_switch', payload '{"linkquality":150,"power_on_behavior":null,"state":"OFF"}'
[2026-09-10 03:13:32] error: 	zh:zstack:znp: Socket error Error: read ETIMEDOUT
[2026-09-10 03:13:32] info: 	zh:zstack:znp: Port closed
[2026-09-10 03:13:32] info: 	zh:zstack:znp: closing
[2026-09-10 03:13:32] error: 	z2m: Adapter disconnected, stopping
[2026-09-10 03:13:32] info: 	z2m: Stopping Zigbee2MQTT (restart=false, code=2, signal=undefined)
[2026-09-10 03:13:32] info: 	z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload '{"state":"offline"}'
[2026-09-10 03:13:32] info: 	z2m: Disconnecting from MQTT server
[2026-09-10 03:13:32] info: 	z2m: Stopping zigbee-herdsman...
[2026-09-10 03:13:32] info: 	z2m: Stopped zigbee-herdsman
[2026-09-10 03:13:32] info: 	z2m: Stopped Zigbee2MQTT
WATCHDOG: Waiting 0.03333333333333333min before next start try.
Starting Zigbee2MQTT with watchdog (2000,60000,300000,900000,1800000,3600000).
[2026-09-10 03:13:34] info: 	z2m: Logging to console, file (filename: log.log)
[2026-09-10 03:13:34] info: 	z2m: Starting Zigbee2MQTT version 2.14.1 (commit #unknown)
[2026-09-10 03:13:34] info: 	z2m: Starting zigbee-herdsman (10.9.2)
[2026-09-10 03:13:34] info: 	zh:zstack:znp: Opening TCP socket with 192.168.10.7:6638
[2026-09-10 03:13:42] error: 	zh:zstack:znp: Socket error Error: connect EHOSTUNREACH 192.168.10.7:6638
[2026-09-10 03:13:42] error: 	z2m: Error while starting zigbee-herdsman
[2026-09-10 03:13:42] error: 	z2m: Failed to start zigbee-herdsman
[2026-09-10 03:13:42] error: 	z2m: Check https://www.zigbee2mqtt.io/guide/installation/20_zigbee2mqtt-fails-to-start_crashes-runtime.html for possible solutions
[2026-09-10 03:13:42] error: 	z2m: Exiting...
[2026-09-10 03:13:42] error: 	z2m: Error: Error while opening socket
    at Socket.<anonymous> (/app/node_modules/.pnpm/zigbee-herdsman@10.9.2/node_modules/zigbee-herdsman/src/adapter/z-stack/znp/znp.ts:160:24)
    at Socket.emit (node:events:521:24)
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
[2026-09-10 03:13:42] info: 	zh:zstack:znp: Port closed
node:events:487
      throw er; // Unhandled 'error' event
      ^
NodeError: write after end
    at writeAfterEnd (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_writable.js:264:12)
    at Writable.write (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_writable.js:300:21)
    at DerivedLogger.ondata (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:629:20)
    at DerivedLogger.emit (node:events:521:24)
    at addChunk (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:279:12)
    at readableAddChunk (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:262:11)
    at Readable.push (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:228:10)
    at Transform.push (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_transform.js:132:32)
    at DerivedLogger._transform (/app/node_modules/.pnpm/winston@3.19.0/node_modules/winston/lib/winston/logger.js:337:12)
    at Transform._read (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_transform.js:166:10)
Emitted 'error' event on DerivedLogger instance at:
    at DerivedLogger.transportEvent (/app/node_modules/.pnpm/winston@3.19.0/node_modules/winston/lib/winston/logger.js:663:12)
    at File.emit (node:events:521:24)
    at errorOrDestroy (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/internal/streams/destroy.js:90:101)
    at writeAfterEnd (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_writable.js:266:3)
    at Writable.write (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_writable.js:300:21)
    at DerivedLogger.ondata (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:629:20)
    at DerivedLogger.emit (node:events:521:24)
    at addChunk (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:279:12)
    at readableAddChunk (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:262:11)
    at Readable.push (/app/node_modules/.pnpm/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js:228:10)
Node.js v24.18.1
What did you expect to happen?

No response

How to reproduce it (minimal and precise)

No response

Zigbee2MQTT version

2.14.1-1

Adapter firmware version

20260311

Adapter

SLZB-06p7U

Setup

Add-on on Home Assistant using Home Assistant OS (in a x86_64 VM)

Device database.db entry

No response

Debug log

No response

Notes

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with zigbee-herdsman/src/adapter/z-stack/znp/znp.ts at the reported socket-opening failure around line 160, then trace how Zigbee2MQTT handles startup errors and logger shutdown. Reproduce an unreachable adapter during startup if possible. Done means the failed connection does not cause an unhandled “write after end” crash, allowing the Home Assistant watchdog to restart Zigbee2MQTT.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.