-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled promise rejection when stopping the coordinator #555
Comments
Can you provide the herdsman debug logging of this? Run your process with |
Here is the log output. I marked the point at which the
|
@ChrisHae since this is in the deconz adapter code, can you take a look at this? |
I think I figured out why it crashes. In line 101 of |
Okay I did some investigation now and that was actually not the reason - although I see this as a problem and there should maybe an I found a simple workaround (or fix?) by changing
to This will stop the queue processing and error rejection. Additionally, now the loop terminates gracefully. If later calling
But as I said before I don't know what is more suitable. Also I found similar occurrences in lines 622 and 964 that look almost equally to me. While reading the code I also saw some vague expressions that looked a little suspicious to me for unhandled rejections but they were not of importance here. If you are interested, I can have a look at it again and create an MR but idk how this is done on GitHub tbh. EDIT: It must be the second variant. Otherwise it breaks communication with my devices. But still, after re-opening the controller, I run into problems. But that could also be a problem of my application. |
Finally I got a better workaround (maybe this time we could even call it a fix). The problem was that there were arrays that were used by a controller instance but declared module-wide so that they are shared even if a new controller is instantiated after stopping the old one. I just set the length of all arrays to 0 (deletes all entries without destroying references), plus, I put all setInterval() calls in an array and cleared the intervals when 'closed' is emitted. Currently, the intervals get orphans after the driver was closed, probably still consuming CPU time. |
I've added the await, can you check if it is fixed now? |
I already tested that yesterday and that was not the reason why it crashed (as I mentioned in #555 (comment)). But anyways, probably good that it is added now. In the comment linked were the steps explained that I did to make it working. And finally I found a decent solution as explained in #555 (comment). Seems like you have missed these somehow. |
I see your solution but this still looks a bit hacky to me, can we clear these arrays on a stop in the adapter code? |
Jup, this is exactly what I am doing:
Or are you concerned about the fact that it is hooked into the event emitter? We could also put this directly inside the stop function. But the |
This looks good to me, could you make a pr? |
I wanted to push the commit to a new branch but got a 403. Should I fork the project instead and create a PR then? I am coming from Gitlab and actually don't know how to create the PR properly. |
If it's easier, I zipped the file (.ts not supported) instead. |
You can click the edit icon here: https://github.com/Koenkk/zigbee-herdsman/blob/master/src/adapter/deconz/driver/driver.ts (pencil) then make a pr |
Deconz driver: Clear intervals and shared arrays after close; catch all unhandled promises and forward errors to debugger
Wow! Didn't know of that. Thanks. |
Thanks for the mr, I assume this can be closed now. |
Hi, The problem recurs when using socket port instead of serial port. The socket was destroyed before clearing intervals ?? Here is the full debug log:
|
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:
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:
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.
The text was updated successfully, but these errors were encountered: