fix(unifi-protect): stop keying device identity on DHCP host/IP#2082
fix(unifi-protect): stop keying device identity on DHCP host/IP#2082nberardi wants to merge 1 commit into
Conversation
getNativeId matched cameras on host (IP) as a fallback identity key. IPs are not stable: when DHCP recycles an address, a newly provisioned camera resolves to an unrelated camera's nativeId. cleanDict() then overwrites the original camera's mac/anonymousDeviceId entries, collapsing two cameras onto one Scrypted device and dropping the other from the device list. Match only on stable hardware identifiers (mac, anonymousDeviceId, id) and stop maintaining the host map.
|
agreed that its are not stable but neither are these fwiw...
|
|
You're right that "stable" was the wrong word, none of these are immutable. The bug isn't about stability, it's cross-device collision:
mac/anonymousDeviceId/id can each change for a device (the recovery case the map handles), but I can reword "stable", since that appears to be the wrong framing. |
Problem
The Unifi Protect plugin was silently dropping cameras from the device list — a 13-camera NVR surfaced only 11 in Scrypted, and one device rendered an unrelated camera's stream under the wrong name.
Root cause is in
getNativeId(plugins/unifi-protect/src/main.ts). When resolving a camera to its persistent ScryptednativeId, the lookup fell back to matching onhost(the camera's IP address):IPs are not stable. When DHCP recycles an address, a newly provisioned camera that picks up a previously-used IP resolves to the prior camera's
nativeId. The subsequentcleanDict()pass then deletes the original camera'smac/anonymousDeviceIdentries and rebinds them to the new camera — collapsing two distinct cameras onto a single Scrypted device and dropping the other from the device list entirely.This was confirmed against a real affected install: three live camera IDs had all been mapped to one camera's
nativeIdinidToNativeId, and the displaced camera's MAC was missing fromidMaps.mac(overwritten bycleanDict). The symptom — two missing cameras plus one device streaming the wrong feed under the wrong name — matched exactly.Fix
Match device identity only on stable hardware identifiers:
mac,anonymousDeviceId, andid. Stop usinghostas an identity key, and stop maintaining theidMaps.hostmap.Notes
hostremains in thegetNativeIdparameter type since callers still pass device objects that carry it; it is simply no longer used for matching.idMaps.hostin storage. It is now inert (nothing reads it) and harmless, so no migration is included. Affected installs self-heal on the nextgetNativeIdwrite once the stale entry no longer participates in matching; a previously-collapsed device can be re-added via discovery.