Bluebie / homebridge-miio

Xiaomi Mi Home Plugin for Homebridge
112 stars 26 forks source link

Reliability problem when running on linux with avahi providing mdns #9

Closed aguedob closed 7 years ago

aguedob commented 7 years ago

Those are the errors that appears in logs: Apr 02 08:03:07 raspberrypi avahi-daemon[3652]: server.c: Packet too short or invalid while reading response record. (Maybe a UTF-8 problem?) Apr 02 08:03:08 raspberrypi avahi-daemon[3652]: server.c: Packet too short or invalid while reading response record. (Maybe a UTF-8 problem?) Apr 02 08:03:10 raspberrypi avahi-daemon[3652]: server.c: Packet too short or invalid while reading response record. (Maybe a UTF-8 problem?) Apr 02 08:03:12 raspberrypi homebridge[8570]: events.js:163 Apr 02 08:03:12 raspberrypi homebridge[8570]: throw er; // Unhandled 'error' event Apr 02 08:03:12 raspberrypi homebridge[8570]: ^ Apr 02 08:03:12 raspberrypi homebridge[8570]: Error: dns service error: unknown Apr 02 08:03:12 raspberrypi homebridge[8570]: at MDNSService.on_resolver_done (/usr/lib/node_modules/homebridge-miio/node_modules/mdns/lib/resolver_sequence_tasks.js:19:30) Apr 02 08:03:12 raspberrypi homebridge[8570]: at SocketWatcher.MDNSService.self.watcher.callback (/usr/lib/node_modules/homebridge-miio/node_modules/mdns/lib/mdns_service.js:18:40) Apr 02 08:03:12 raspberrypi systemd[1]: homebridge.service: main process exited, code=exited, status=1/FAILURE

I've also checked with tcpdump that avahi-daemon error messages match with the following packets: 08:03:07.767267 IP 192.168.1.8.5353 > 224.0.0.251.5353: 0- [0q] 5/0/0 (Cache flush) A 192.168.1.8, (Cache flush) SRV chuangmi-plug-m1_miio52735560.local.:54321 0 0, PTR chuangmi-plug-m1_miio52735560._miio._udp.local., (Cache flush) TXT "poch=0:mac=286c07a02fc0^@^E_miio^D_udp^Elocal^@^@^L^@^A^@^@^@M-^?^@0^]chuangmi-plug-m1_miio52735560^E_miio^D_udp^Elocal^@[|domain] 08:03:08.936266 IP 192.168.1.8.5353 > 224.0.0.251.5353: 0- [0q] 5/0/0 (Cache flush) A 192.168.1.8, (Cache flush) SRV chuangmi-plug-m1_miio52735560.local.:54321 0 0, PTR chuangmi-plug-m1_miio52735560._miio._udp.local., (Cache flush) TXT "poch=0:mac=286c07a02fc0^@^E_miio^D_udp^Elocal^@^@^L^@^A^@^@^@M-^?^@0^]chuangmi-plug-m1_miio52735560^E_miio^D_udp^Elocal^@[|domain] 08:03:10.847970 IP 192.168.1.8.5353 > 224.0.0.251.5353: 0*- [0q] 5/0/0 (Cache flush) A 192.168.1.8, (Cache flush) SRV chuangmi-plug-m1_miio52735560.local.:54321 0 0, PTR chuangmi-plug-m1_miio52735560._miio._udp.local., (Cache flush) TXT "poch=0:mac=286c07a02fc0^@^E_miio^D_udp^Elocal^@^@^L^@^A^@^@^@M-^?^@0^]chuangmi-plug-m1_miio52735560^E_miio^D_udp^Elocal^@[|domain]

aguedob commented 7 years ago

I managed to get it working on OSX without any issues, so seems to be related with raspberry pi avahi-daemon.

Bluebie commented 7 years ago

Yeah i'm not really sure. It does seem to be specific to Avahi as an mdns implementation, when avahi becomes inaccessible on the local system. Related to https://github.com/volumio/Volumio2/issues/40

Maybe there's something that could be done in the library to work around this problem? volumio has some error handling which seems to pretty much amount to "catch the error and just tell it to try again" but that sounds scarily like it could cause crazy infinite loops if avahi is just totally down. https://github.com/volumio/Volumio2/blob/982d6ea2ae169b6d139866336b0ea81141ddc0de/app/plugins/system_controller/volumiodiscovery/index.js#L194

Bluebie commented 7 years ago

this should be resolved if you update to version 0.2.0 which does not use mdns