zigbee-herdsman: Unhandled promise rejection when stopping the coordinator

Hey, I encountered a bug today where my Node process exited due to an unhandled promise rejection and finally found out that stopping the coordinator was the cause.

Following code can reproduce the issue:

const {Controller} = require("zigbee-herdsman");

const coordinator = new Controller({
    databasePath: 'test.db',
    serialPort: {path: '/dev/ttyACM0'}
});

let date = new Date();

coordinator
    .start()
    .then(() => {
        coordinator.stop()
            .then(() => console.log("Stopped", new Date() - date))
            .catch(err => console.log("Catch error (2):", new Date() - date, err));
        console.log("Controller created", new Date() - date);
    })
    .catch(err => console.log("Catch error (1):", new Date() - date, err))

I added dates for debugging purposes but when the app crashes no error handler is invoked. I used my stopwatch and it takes 10 seconds to crash. Output:

Controller created 211
Stopped 319
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TIMEOUT".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

I tried to get the stack using the unhandled rejection event but it was undefined, I do not know where to search. It would be nice to restart the controller without terminating Node itself. I am using CC253X with DECONZ Adapter.

Maybe this information is helpful to debug the problem. If you have any further questions, let me know. I am using v0.14.40 and the test.db file had no previous devices in it.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (16 by maintainers)

Commits related to this issue

Most upvoted comments

This looks good to me, could you make a pr?

I think I figured out why it crashes. In line 101 of src/adapter/deconz/adapter/deconzAdapter.ts there is a missing await for the drivers close function. But close() returns a promise that is not returned or caught. So if it rejects, Node will terminate. Of course that still would mean that close() throws an error but that would probably be another topic. I will do some testing on the next days when I have more time and let you know.