seydx / homebridge-star-projector

Homebridge plugin for controlling tuya/smartlife based star projectors
MIT License
41 stars 2 forks source link

Plugin causes homebridge to crash while startup #2

Closed sschuste closed 3 years ago

sschuste commented 3 years ago

Describe the bug In case the internet connection is interrupted, the Homebridge cannot be restarted because the plugin cannot connect to the Tuya API.

To Reproduce

  1. Disconnect the internet connection
  2. Restart homebridge
  3. Watch the homebridge log

Expected behavior I expected the plugin not to crash

Log

[30/05/2021, 08:45:43] [StarProjector] Sterne: An error occured during connecting to Tuya API
[30/05/2021, 08:45:43] [StarProjector] Error: find() timed out. Is the device powered on and the ID or IP correct?
    at /usr/local/lib/node_modules/homebridge-star-projector/node_modules/tuyapi/index.js:824:13
    at Timeout._onTimeout (/usr/local/lib/node_modules/homebridge-star-projector/node_modules/p-timeout/index.js:25:13)
    at listOnTimeout (internal/timers.js:555:17)
    at processTimers (internal/timers.js:498:7)
[30/05/2021, 08:45:43] [StarProjector] Sterne: Error from socket: connect ECONNREFUSED 127.0.0.1:6668
[30/05/2021, 08:45:53] [StarProjector] Sterne: Error from socket: connect ECONNREFUSED 127.0.0.1:6668
[30/05/2021, 08:45:57] [StarProjector] Sterne: Error from socket: connect ECONNREFUSED 127.0.0.1:6668
[30/05/2021, 08:46:05] [StarProjector] Sterne: Error from socket: connect ECONNREFUSED 127.0.0.1:6668
[30/05/2021, 08:46:21] [StarProjector] Sterne: Error from socket: connect ECONNREFUSED 127.0.0.1:6668
Error: connect ECONNREFUSED 127.0.0.1:6668
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 6668,
  attemptNumber: 6,
  retriesLeft: 0
}
Error: connect ECONNREFUSED 127.0.0.1:6668
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 6668,
  attemptNumber: 6,
  retriesLeft: 0
}
[30/05/2021, 08:46:21] Got SIGTERM, shutting down Homebridge...

Impact: Parts of the home automation are no longer available, automations no longer work, and I can't even turn off the light in the dining room, which can be quite annoying ;-). As a result, the Homebridge becomes dependent on an existing internet connection, which contradicts the HomeKit idea.

seydx commented 3 years ago

Thanks @sschuste for reporting this. I have now added a first fix and reworked the whole connection/reconnection logic. Could you install the latest beta version and give a short feedback if the bug is fixed or not?

(sudo) npm i -g homebridge-star-projector@beta
sschuste commented 3 years ago

Installed the beta, killed my internet connection, restarted Homebridge and the result is: thumbs up. It now works as expected. Thank you.

seydx commented 3 years ago

Thanks for the feedback. The changes are live now in v1.0.5