-
Notifications
You must be signed in to change notification settings - Fork 352
fix: guard against a undefined device on data receipt
#1580
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
Conversation
|
The endpoint is currently safe - on the issue (#1574) there was the idea to skip endpoint creation here and instead return early. I can include that in this PR too if desired zigbee-herdsman/src/controller/controller.ts Lines 1021 to 1028 in db634fd
|
db634fd to
adac765
Compare
|
Should check against |
Thanks for the quick review - I went for
Sounds good, I've made those changes. Will sort out linting/format/tests if this change is more along the right lines |
adac765 to
465805d
Compare
|
Have to use But I think we need a more complex mechanism to properly check the state. There are several things to fix though:
For the RCs, we need to come up with a good way to test this, so we can catch at least the major edge-cases, have a better idea of where things can go wrong exactly. i.e. write tests to find the bugs @Koenkk any ideas? |
|
I think it will be very hard to prevent all the race conditions unless we decide to also return deleted device in
|
|
Can't return deleted device there, we'd end up triggering logic for devices we don't want to. In Controller ZCL listener, we have a valid Device: zigbee-herdsman/src/controller/controller.ts Lines 998 to 1000 in dec6584
we then grab the Endpoint (or create it): zigbee-herdsman/src/controller/controller.ts Line 1019 in dec6584
we call the ZCL listener for the Device, we pass a valid Endpoint: zigbee-herdsman/src/controller/controller.ts Line 1127 in dec6584
At some point after first snippet but before here, the device moved from we call
getDevice() only grabs non-deleted Device BUT assumes Device is always present (save for the extra logging we added):zigbee-herdsman/src/controller/model/endpoint.ts Lines 192 to 203 in dec6584
Since Endpoint should never be present without a Device, it's a good assumption, except when we carry an Endpoint ref for too long without checking if the Device got deleted. Of course the simplest of fix for this scenario, would just be to (not sure why it isn't like that in the first place btw): - endpoint.getDevice().manufacturerName
+ this.manufacturerNameBut it won't solve the RC problem (nor the other possible RCs). It won't fail, but it will keep processing stuff for a deleted device (and potentially make a mess in Z2M/ZHC since they expect emitted stuff & co to be from valid devices, not to mention network requests to a device that no longer is present). Maybe we start by fixing the first two points I mentioned in previous post, plus add a return |
What kind of logic? |
|
I'm not sure I understood what you meant, because this would be everything really, from unnecessary/invalid MQTT publishing, to requests to devices that left the network (i.e. 100% fail)... |
for example, if we're deleting or delete-pending a device
465805d to
2c1d081
Compare
|
I think this should cover most cases. It's not perfect, still probably several ways to RC, but it should better handle the case of Note: |
I guess this isn't really something we can enforce either - I had thought about forcing access to go through a sync function: -device.getEndpoint(...)
+device.withEndpoint(endpoint => { // can't be async by the typesystem
+ ...
+})but the same problem exists in that the |
|
Thanks! |
for example, if we're deleting or delete-pending a device
closes #1574