question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: DuplicateDeviceError crashes library

See original GitHub issue

Client version

2.1.0

Node version

16.13

Operating System type

Linux

Operating system version

Debian

Describe the bug

See code snippet from eufysecurity.ts (lines 495 ff.):

            promises.push(new_device.then((device: Device) => {
                device.on("property changed", (device: Device, name: string, value: PropertyValue) => this.onDevicePropertyChanged(device, name, value));
                device.on("raw property changed", (device: Device, type: number, value: string) => this.onDeviceRawPropertyChanged(device, type, value));
                device.on("crying detected", (device: Device, state: boolean) => this.onDeviceCryingDetected(device, state));
                device.on("sound detected", (device: Device, state: boolean) => this.onDeviceSoundDetected(device, state));
                device.on("pet detected", (device: Device, state: boolean) => this.onDevicePetDetected(device, state));
                device.on("motion detected", (device: Device, state: boolean) => this.onDeviceMotionDetected(device, state));
                device.on("person detected", (device: Device, state: boolean, person: string) => this.onDevicePersonDetected(device, state, person));
                device.on("rings", (device: Device, state: boolean) => this.onDeviceRings(device, state));
                device.on("locked", (device: Device, state: boolean) => this.onDeviceLocked(device, state));
                device.on("open", (device: Device, state: boolean) => this.onDeviceOpen(device, state));
                device.on("ready", (device: Device) => this.onDeviceReady(device));
                this.addDevice(device);
                return device;
            }).catch((device: Device) => {
                this.log.error("Error", device);
                return device;
            }));
        }
    }
    this.loadingDevices = Promise.all(promises).then((devices) => {
        devices.forEach((device) => {
            const station = this.getStation(device.getStationSerial());
            if (!station.isConnected()) {
                station.setConnectionType(this.config.p2pConnectionSetup);
                station.connect();
            }
        });
        this.loadingDevices = undefined;
    });

and the corresponding addDevice method:

private addDevice(device: Device): void {
    const serial = device.getSerial()
    if (serial && !Object.keys(this.devices).includes(serial)) {
        this.devices[serial] = device;
        this.emit("device added", device);


        if (device.isLock())
            this.mqttService.subscribeLock(device.getSerial());
    } else {
        throw new DuplicateDeviceError(`Device with this serial ${device.getSerial()} exists already and couldn't be added again!`);
    }
}

If the function throws a DuplicateDeviceError. This error is in sequence treated as a device itself (lines 509-511). Since this error object doesn’t have the needed methods for a device the following loadingDevices method will crash.

To reproduce

I have this issue in my quick and dirty tool (https://github.com/thieren/eufy-test-client) even though I can’t quite tell why. The first login works fine but any subsequent attempt to connect crashes.

The homebridge-eufy-security client which establishes the connection just the same works fine it seems.

Screenshots & Logfiles

TypeError: device.getStationSerial is not a function
    at /home/rene/dev/etc/node_modules/eufy-security-client/build/eufysecurity.js:477:56
    at Array.forEach (<anonymous>)
    at /home/rene/dev/etc/node_modules/eufy-security-client/build/eufysecurity.js:476:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async EufySecurity.getDevices (/home/rene/dev/etc/node_modules/eufy-security-client/build/eufysecurity.js:276:13)
    at async EufyPlatform.updateDevices (/home/rene/dev/etc/index.js:299:25)
    at async EufySecurity.<anonymous> (/home/rene/dev/etc/index.js:143:7)

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bropatcommented, Jun 14, 2022

So, since you shouldn’t use the refreshCloudData method in the first place, how are you supposed to get a stations and device list at the start of the program?

The connect event is now emitted after the internal refresh.

My assumption would be, that you’ll consider an async approach and waiting on ‘device added’ and ‘station added’ events is best practice? Am I right?

Right. There are also “old” methods that I would like to remove in the next major release.

Alternatively, would it be feasible to emit an event after the first call to refreshCloudData has read all the devices?

You could now also use the connect event 😉

1reaction
thierencommented, Jun 13, 2022

Thank you for auditing.

Yeah. Didn’t check if refresh was really necessary and copied it from other sources nevertheless.

As said quick and (very) dirty. But helps me a lot to test things and dive a little deeper.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automation client receives an error message or crashes ...
BUG : Automation client receives an error message or crashes when the ... The following GUIDs are duplicated in the Excel 5.0 type...
Read more >
Support7Demos crash pressing the options menu hardware ...
The crash happens on Android 4.1 device pressing the options menu hardware button, running the ActionBarUsage included in the Support7Demos from the latest ......
Read more >
When should standard library functions crash? - Discussion
Is there a standard lib guideline on when a function can/should crash? ... Dictionary.init(uniqueKeysAndValues:) crashes on duplicate keys.
Read more >
87557: MySQL Instance crashes randomly
Description: We got several MySQL Servers version 5.5.54 running on Ubuntu Trusty. They are clustered via galera-3 version 25.3.20 from ...
Read more >
Node crashes when a duplicate data is inserted into ...
Though, in general, the error says that the email you are trying to create a user with already exists in your collection, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found