dehsgr / node-red-contrib-evohome

This provides nodes for controlling Honeywell Evohome
ISC License
5 stars 7 forks source link

TypeError: Cannot read property '_renew' of undefined #10

Closed PaulD987 closed 3 years ago

PaulD987 commented 3 years ago
2021-10-09T16:02:28.690286590Z Renewed Honeywell API authentication token!
2021-10-09T16:31:58.359581423Z 9 Oct 16:31:58 - [warn] [evohome-status:8d44702b.afa9a8] Renewing Honeywell API authentication token failed:
2021-10-09T17:01:26.714234164Z 9 Oct 17:01:26 - [red] Uncaught Exception:
2021-10-09T17:01:26.762707231Z 9 Oct 17:01:26 - TypeError: Cannot read property '_renew' of undefined
2021-10-09T17:01:26.762754899Z     at renewSession (/data/node_modules/node-red-contrib-evohome/evohome/evohome-status.js:91:21)
2021-10-09T17:01:26.762764589Z     at Timeout._onTimeout (/data/node_modules/node-red-contrib-evohome/evohome/evohome-status.js:98:25)
2021-10-09T17:01:26.762773188Z     at ontimeout (timers.js:436:11)
2021-10-09T17:01:26.762781269Z     at tryOnTimeout (timers.js:300:5)
2021-10-09T17:01:26.762789262Z     at listOnTimeout (timers.js:263:5)
2021-10-09T17:01:26.762797077Z     at Timer.processTimers (timers.js:223:10)

Node-Red server failed due to unhandled exception. Maybe caused by the renewing of the token failing at 16:31... I believe I am on the latest version available. We try to debug if I have a chance.

PaulD987 commented 3 years ago

So, the problem here is that when the refreshing of the token failed at 16:31:58, it went into the fail() method. This cleared the global evohome-session variable, however, it didn't stop the timer, so renewSession was called again at the session.refreshTokenInterval interval. Two things here seem appropriate. Firstly, when renewSession is called by the timer, check that there is actually a session (it could have been cleared somewhere else without the timer being stopped). And secondly, stop the timer before trying to renew the session. If the session renews successfully, a new timer will be created anyway, and if the renewal fails, then we don't want the timer at that point anyway!

dehsgr commented 3 years ago

Thanks for fixing this issue. I'll publish a NPM update soon.