hassio-zigbee2mqtt icon indicating copy to clipboard operation
hassio-zigbee2mqtt copied to clipboard

z2m: Error: Error while opening socket

Open magiva opened this issue 1 year ago • 2 comments

Description of the issue

addon wont start it Was running, i added the first device and now it wont start

Addon version

1.40.2-1

Platform

Core 2024.10.1 Supervisor 2024.10.0 Operating System 13.1 Frontend 20241002.2

Logs of the issue (if applicable)

[16:39:59] INFO: Preparing to start... [16:40:00] INFO: Socat not enabled [16:40:00] INFO: Starting Zigbee2MQTT... Starting Zigbee2MQTT without watchdog. [2024-10-09 16:40:02] info: z2m: Logging to console, file (filename: log.log) [2024-10-09 16:40:02] info: z2m: Starting Zigbee2MQTT version 1.40.2 (commit #unknown) [2024-10-09 16:40:02] info: z2m: Starting zigbee-herdsman (2.1.3) [2024-10-09 16:40:02] info: zh:zstack:znp: Opening TCP socket with slzb-06.local:6638 [2024-10-09 16:40:02] info: zh:zstack:znp: Socket connected [2024-10-09 16:40:02] info: zh:zstack:znp: Socket ready [2024-10-09 16:40:02] info: zh:zstack:znp: Writing CC2530/CC2531 skip bootloader payload [2024-10-09 16:40:02] info: zh:zstack:znp: Socket error [2024-10-09 16:40:02] error: z2m: Error while starting zigbee-herdsman [2024-10-09 16:40:02] error: z2m: Failed to start zigbee [2024-10-09 16:40:02] error: z2m: Check https://www.zigbee2mqtt.io/guide/installation/20_zigbee2mqtt-fails-to-start.html for possible solutions [2024-10-09 16:40:02] error: z2m: Exiting... [2024-10-09 16:40:02] error: z2m: Error: Error while opening socket at Socket. (/app/node_modules/zigbee-herdsman/src/adapter/z-stack/znp/znp.ts:166:24) at Socket.emit (node:events:529:35) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at processTicksAndRejections (node:internal/process/task_queues:82:21)

/app/node_modules/winston/node_modules/readable-stream/lib/_stream_writable.js:264 var er = new ERR_STREAM_WRITE_AFTER_END(); ^ Error: write after end at writeAfterEnd (/app/node_modules/winston/node_modules/readable-stream/lib/_stream_writable.js:264:12) at DerivedLogger.Writable.write (/app/node_modules/winston/node_modules/readable-stream/lib/_stream_writable.js:300:21) at DerivedLogger.log (/app/node_modules/winston/lib/winston/logger.js:231:12) at Logger.log (/app/lib/util/logger.ts:198:25) at Logger.info (/app/lib/util/logger.ts:211:14) at Znp.onPortClose (/app/node_modules/zigbee-herdsman/src/adapter/z-stack/znp/znp.ts:96:16) at Object.onceWrapper (node:events:632:26) at Socket.emit (node:events:517:28) at TCP. (node:net:350:12)

magiva avatar Oct 09 '24 14:10 magiva

having the same issue,

technically, the error message seems like an issue with async in NodeJS https://stackoverflow.com/questions/27769842/write-after-end-error-in-node-js-webserver

i have a similar issue running here, maybe i chose the wrong repo (zigbee2mqtt vs hassio-zigbee2mqtt): https://github.com/Koenkk/zigbee2mqtt/issues/24154#issuecomment-2416654070

indexample avatar Oct 16 '24 13:10 indexample

The real error is [2024-10-09 16:40:02] info: zh:zstack:znp: Socket error, meaning it cannot connect to the dongle, I've extended the error logging a bit, can you see what is logged now?

Changes will be available in the dev branch in a few hours from now.

Koenkk avatar Oct 18 '24 18:10 Koenkk

i have tried with the dev branch / edge it runs for about 5 and a half minutes, then: Socket error Error: read ECONNRESET


[2024-10-23 08:59:55] info: 	z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Kantoorlamp1', payload '{"backlight_mode":"inverted","linkquality":167,"power_on_behavior":"previous","state":"ON"}'
[2024-10-23 09:04:02] error: 	zh:zstack:znp: Socket error Error: read ECONNRESET
[2024-10-23 09:04:02] info: 	zh:zstack:znp: Port closed
[2024-10-23 09:04:02] info: 	zh:zstack:znp: closing
[2024-10-23 09:04:02] error: 	z2m: Adapter disconnected, stopping
[2024-10-23 09:04:02] info: 	z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload '{"state":"offline"}'
[2024-10-23 09:04:02] info: 	z2m: Disconnecting from MQTT server
[2024-10-23 09:04:02] info: 	z2m: Stopping zigbee-herdsman...
[2024-10-23 09:04:02] info: 	z2m: Stopped zigbee-herdsman
[2024-10-23 09:04:02] info: 	z2m: Stopped Zigbee2MQTT

indexample avatar Oct 23 '24 07:10 indexample

That indicates your network connection is not stable

Koenkk avatar Oct 23 '24 19:10 Koenkk

Any test you recommend that would convince you the network is stable?

Im running quite a large setup and this is the only one with issues

indexample avatar Oct 28 '24 18:10 indexample

It could also be an issue of the coordinator itself, in the past I read people having these issues when opening the web page of the coordinator.

Koenkk avatar Oct 29 '24 19:10 Koenkk

i think i worked it out, and if so, it was a network issue indeed.

after diving into it more, there was a warning in my unify switch portal: Multiple devices are using the same IP address: 192.168.2.X. Please check each device's configuration to ensure none are communicating with a rogue DHCP server.

the coordinator had hardcoded ip/dhcp settings, and the same static lease from router, but with different MAC address. For some reason the coordinator had gotten a different mac address over time (should these not be stable per device?!), which i believe would be the cause for this issue (in combination with the settings).

now, after changing the coordinator to dhcp settings, the addon has been running well for over 1hr.

indexample avatar Oct 30 '24 12:10 indexample

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Nov 30 '24 00:11 github-actions[bot]

I suddenly ran into the same issue today. For me it definitely wasn't network related. Restarting the device did not fix the issue. What did solve it was setting the device to usb mode and back to network. Afterwards z2m was able to connect again. So it's definitely an issue with the slzb6 firmware getting stuck.

lhw avatar Jan 16 '25 22:01 lhw

I reverted back to V2.6.8.dev26 in the slzb6. Since I had done an update of the slzb6 firmware nothing worked in my Home Assistant.

andlinux007 avatar Jan 21 '25 17:01 andlinux007

Today after the update errors appeared:

[17:26:18]`` INFO: Preparing to start...
[17:26:18] INFO: Socat not enabled
[17:26:18] INFO: Starting Zigbee2MQTT...
Starting Zigbee2MQTT without watchdog.
[2025-01-21 17:26:22] info: 	z2m: Logging to console, file (filename: log.log)
[2025-01-21 17:26:22] info: 	z2m: Starting Zigbee2MQTT version 2.0.0 (commit #unknown)
[2025-01-21 17:26:22] info: 	z2m: Starting zigbee-herdsman (3.2.1)
[2025-01-21 17:26:23] info: 	zh:zstack:znp: Opening TCP socket with 192.168.0.13:6638
[2025-01-21 17:26:23] info: 	zh:zstack:znp: Socket connected
[2025-01-21 17:26:23] info: 	zh:zstack:znp: Socket ready
[2025-01-21 17:26:23] info: 	zh:zstack:znp: Writing CC2530/CC2531 skip bootloader payload
[2025-01-21 17:26:23] error: 	zh:zstack:znp: Socket error Error: read ECONNRESET
[2025-01-21 17:26:23] error: 	z2m: Error while starting zigbee-herdsman
[2025-01-21 17:26:23] error: 	z2m: Failed to start zigbee-herdsman
[2025-01-21 17:26:23] error: 	z2m: Check https://www.zigbee2mqtt.io/guide/installation/20_zigbee2mqtt-fails-to-start_crashes-runtime.html for possible solutions
[2025-01-21 17:26:23] error: 	z2m: Exiting...
[2025-01-21 17:26:23] error: 	z2m: Error: Error while opening socket
 at Socket.<anonymous> (/app/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/src/adapter/z-stack/znp/znp.ts:158:24)
 at Socket.emit (node:events:530:35)
 at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at processTicksAndRejections (node:internal/process/task_queues:90:21)
/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_writable.js:264
 var er = new ERR_STREAM_WRITE_AFTER_END();
Error: write after end
  at writeAfterEnd (/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_writable.js:264:12)
 at DerivedLogger.Writable.write (/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_writable.js:300:21)
 at DerivedLogger.log (/app/node_modules/.pnpm/[email protected]/node_modules/winston/lib/winston/logger.js:231:12)
  at Logger.log (/app/lib/util/logger.ts:198:25)
 at Logger.info (/app/lib/util/logger.ts:211:14)
  at Znp.onPortClose (/app/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/src/adapter/z-stack/znp/znp.ts:88:16)  
 at Object.onceWrapper (node:events:633:26)
 at Socket.emit (node:events:518:28)
  at TCP.<anonymous> (node:net:343:12)

No changes helped, only this advice helped, I sincerely thank the author.

I suddenly ran into the same issue today. For me it definitely wasn't network related. Restarting the device did not fix the issue. What did solve it was setting the device to usb mode and back to network. Afterwards z2m was able to connect again. So it's definitely an issue with the slzb6 firmware getting stuck.

Originally posted by @lhw in #644

Tomasz720 avatar Jan 21 '25 17:01 Tomasz720

For what it's worth, I ran into this issue after updating to firmware 2.7.0. The fix for me after much time digging was to change the ip address of the SLZB. Increased it by one, edited it in Z2M and all is well.

subseatech avatar Jan 22 '25 00:01 subseatech

Same issue here with SLZB-06 on 2.7.0 - switching to USB mode and back didn't work for me (if you do this and don't have easy access to use USB with your SLZB, make sure you enable "Keep ON Wi-Fi/Ethernet network & web server in USB mode"!) but removing the static address I had configured in my router and setting a new one solved the problem. Thanks @subseatech and others here!

tempomode avatar Jan 22 '25 09:01 tempomode

Today after the update errors appeared:

[17:26:18]`` INFO: Preparing to start...
[17:26:18] INFO: Socat not enabled
[17:26:18] INFO: Starting Zigbee2MQTT...
Starting Zigbee2MQTT without watchdog.
[2025-01-21 17:26:22] info: 	z2m: Logging to console, file (filename: log.log)
[2025-01-21 17:26:22] info: 	z2m: Starting Zigbee2MQTT version 2.0.0 (commit #unknown)
[2025-01-21 17:26:22] info: 	z2m: Starting zigbee-herdsman (3.2.1)
[2025-01-21 17:26:23] info: 	zh:zstack:znp: Opening TCP socket with 192.168.0.13:6638
[2025-01-21 17:26:23] info: 	zh:zstack:znp: Socket connected
[2025-01-21 17:26:23] info: 	zh:zstack:znp: Socket ready
[2025-01-21 17:26:23] info: 	zh:zstack:znp: Writing CC2530/CC2531 skip bootloader payload
[2025-01-21 17:26:23] error: 	zh:zstack:znp: Socket error Error: read ECONNRESET
[2025-01-21 17:26:23] error: 	z2m: Error while starting zigbee-herdsman
[2025-01-21 17:26:23] error: 	z2m: Failed to start zigbee-herdsman
[2025-01-21 17:26:23] error: 	z2m: Check https://www.zigbee2mqtt.io/guide/installation/20_zigbee2mqtt-fails-to-start_crashes-runtime.html for possible solutions
[2025-01-21 17:26:23] error: 	z2m: Exiting...
[2025-01-21 17:26:23] error: 	z2m: Error: Error while opening socket
 at Socket.<anonymous> (/app/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/src/adapter/z-stack/znp/znp.ts:158:24)
 at Socket.emit (node:events:530:35)
 at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at processTicksAndRejections (node:internal/process/task_queues:90:21)
/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_writable.js:264
 var er = new ERR_STREAM_WRITE_AFTER_END();
Error: write after end
  at writeAfterEnd (/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_writable.js:264:12)
 at DerivedLogger.Writable.write (/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_writable.js:300:21)
 at DerivedLogger.log (/app/node_modules/.pnpm/[email protected]/node_modules/winston/lib/winston/logger.js:231:12)
  at Logger.log (/app/lib/util/logger.ts:198:25)
 at Logger.info (/app/lib/util/logger.ts:211:14)
  at Znp.onPortClose (/app/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/src/adapter/z-stack/znp/znp.ts:88:16)  
 at Object.onceWrapper (node:events:633:26)
 at Socket.emit (node:events:518:28)
  at TCP.<anonymous> (node:net:343:12)

No changes helped, only this advice helped, I sincerely thank the author.

I suddenly ran into the same issue today. For me it definitely wasn't network related. Restarting the device did not fix the issue. What did solve it was setting the device to usb mode and back to network. Afterwards z2m was able to connect again. So it's definitely an issue with the slzb6 firmware getting stuck.

Originally posted by @lhw in #644

Dude. Been hammering away at a similar issue for the better part of the day, your response prompted me to check and iI was set to usb connection. Back up and running. cant thank you enough.

cabooseau avatar Feb 19 '25 05:02 cabooseau

Switching from DHCP to static and back resolved the issue. During the process, I changed the IP, which might have also played a part.

olekgo avatar Mar 29 '25 01:03 olekgo

Nothing works for me. I tried changing from usb to ethernet, dhcp to static, downgrading firmware.

v2.7.0 and 2.8.2dev3

bapesupreme avatar Apr 19 '25 04:04 bapesupreme

Nothing works for me. I tried changing from usb to ethernet, dhcp to static, downgrading firmware.

v2.7.0 and 2.8.2dev3

I'm still on v2.6.8.dev26, if I update it I have the same problem and I tried the things people mention here and on other websites.

andlinux007 avatar Apr 19 '25 05:04 andlinux007

v2.6.8.dev26 worked for me

bapesupreme avatar Apr 19 '25 06:04 bapesupreme

THANK YOU! Indeed it seems that my tidy up end with hitting some button, it was suddently on USB Mode. I switched it to Ethernet again over GUI. Now Works.

THANK YOU !!!!!!! <3

lenusch avatar May 30 '25 21:05 lenusch

I had the same issue and none of the above helped. Then I found the following entry in my SLZB's log: "taskZB | [SOCK IP WHITELIST] Rejected connection from unknown IP". That made me wonder and the I found the cause. I had changed the IP of my Home Assistant OS and forgot that there is the option to only allow a certain IP in the safety settings of SLZB. After I changed that IP to the new HAOS IP, everything worked as it should.

Hopefully that may someday help anyone else, too.

Radieserlbrot avatar Jun 14 '25 18:06 Radieserlbrot

Hello, I had same problem and tested all tips above (and others) without any success. I'd like to share what worked for me. I did a factory reset and did not configure a static ip. I let DHCP activated and a made an ip reservation on the main router instead. My SLZB-06 is now running for 2 days without any error :) I hope my experience can help. Greetings from Belgium. Camomille

Camo1000 avatar Sep 07 '25 10:09 Camo1000