DallasHoff / homebridge-openrgb

Control the RGB lighting of your PC components and peripherals with HomeKit.
https://www.npmjs.com/package/homebridge-openrgb
Apache License 2.0
13 stars 0 forks source link

Plug-in crashing, RangeError: Invalid array length #3

Closed arturoovf closed 2 years ago

arturoovf commented 2 years ago

Today OpenRGB container I use got updated and among new things this version have (03 dic build) adds support for an ssd I have (s40g), but it seems that the updated version or the addition of the new device is crashing the homebridge-openrgb plug-in.

Logs:

[12/3/2021, 11:40:00 PM] Homebridge v1.3.8 (HAP v0.9.7) (OpenRGB) is running on port 54244.

/homebridge/node_modules/homebridge-openrgb/node_modules/openrgb-sdk/src/device.js:79
                flagcheck = Array(8 - flagcheck.length).concat(flagcheck.split("")).reverse()
              ^
RangeError: Invalid array length
    at readModes (/homebridge/node_modules/homebridge-openrgb/node_modules/openrgb-sdk/src/device.js:79:15)
    at new Device (/homebridge/node_modules/homebridge-openrgb/node_modules/openrgb-sdk/src/device.js:21:46)
    at Client.getControllerData (/homebridge/node_modules/homebridge-openrgb/node_modules/openrgb-sdk/src/client.js:78:10)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at OpenRgbPlatform.rgbConnection (/homebridge/node_modules/homebridge-openrgb/src/platform.ts:229:33)
    at OpenRgbPlatform.discoverDevices (/homebridge/node_modules/homebridge-openrgb/src/platform.ts:102:7)
    at HomebridgeAPI.<anonymous> (/homebridge/node_modules/homebridge-openrgb/src/platform.ts:68:9)
[12/3/2021, 11:40:00 PM] [OpenRGB] Child bridge process ended
[12/3/2021, 11:40:00 PM] [OpenRGB] Process Ended. Code: 1, Signal: null`

Plugin Config:

{
    "name": "OpenRGB",
    "discoveryInterval": 600,
    "servers": [
        {
            "name": "ZF7-SERVER",
            "host": "localhost",
            "port": 6742
        }
    ],
    "platform": "OpenRgbPlatform",
    "_bridge": {
        "username": "0E:DA:BB:7C:19:5B",
        "port": 54244
    }
}

Environment: Unraid 6.10rc2, OpenRGB docker container

DallasHoff commented 2 years ago

From the stack trace you posted, I can see that the error is coming from the OpenRGB SDK, not his plugin, so I won't be able to fix it so that the SSD will work correctly with this plugin. The most I can do is stop it from crashing the plugin. I encourage you to open an issue on the OpenRGB SDK's repo about this error. I'll post a fix for the crash in a bit.

arturoovf commented 2 years ago

Thank you for your quick response! I will report it to OpenRGB, thank you for fixing the crash!

Mola19 commented 2 years ago

I think i have fixed the bug in my (very) recent version (openrgb-sdk@0.5.0-beta.2). Could one of you two try it out? The old one is pretty broken, so if it is working it would be a huge improvement to update the package to the newest openrgb-sdk version.

Mola19 commented 2 years ago

Ok i have found another another bug with the same error message for openrgb version smaller than 0.7, i have fixed it in a an new beta version: openrgb-sdk@0.5.0-beta.3

DallasHoff commented 2 years ago

Thanks for your work on the SDK, @Mola19!

@arturoovf Since I don't have the SSD, it would be great if you could test that. If everything looks good to you, I'll make a release of the plugin that uses the new SDK version, along with the better error handling. Here's how you can update your NAS's version of SDK:

In the terminal, navigate to the install directory of the plugin. cd /homebridge/node_modules/homebridge-openrgb

Then, run this (using sudo if necessary) to update the version of the SDK that the plugin uses. npm install openrgb-sdk@0.5.0-beta.3

Finally, restart the Homebridge service and test things out.

arturoovf commented 2 years ago

I followed instructions and everything is working fine as expected (no errors, s40g control works).

Thank you so much both of you for your work on this, that was a very quick response !

Mola19 commented 2 years ago

Thank you for testing. I am making a few test and if successful i will release 0.5.0. My suggestion for you would be to require 0.5 or higher, since i have found some fundamental flaws in my earlier implementation.

DallasHoff commented 2 years ago

About how long until you plan to release 0.5.0? If it's pretty soon, I'll just hold off a bit on making a release so that I can go ahead and include 0.5.0 in it.

Mola19 commented 2 years ago

I hope 1 or 2 days, maybe a week.

Mola19 commented 2 years ago

Also can I see this issue as closed? I would like to close the one on my repo, but I will use this issue to tell you when I have pushed the new version.

DallasHoff commented 2 years ago

I've posted a release with the latest SDK version, but I'm now having my own issues with Homebridge. It could be unrelated, but I'm going to leave this issue open until I have a chance to investigate.

DallasHoff commented 2 years ago

@Mola19 I've had to rollback the SDK version. Something has changed between versions 0.4.3 and 0.5.0 with the connection logic that is causing it to crash the Homebridge process when attempting to connect to a device that is offline.

Previously, I could handle this by timing out the call to the connect method. Now, the call to connect for offline devices succeeds, and the call to getControllerCount crashes the process with the error: Error: getaddrinfo ENOTFOUND dallas-pc.local at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)

Here is the relevant code:

const timeout = async () => await new Promise((resolve, reject) => setTimeout(() => reject(), SERVER_CONNECTION_TIMEOUT));

try {
  await Promise.race([client.connect(), timeout()]);
} catch (err) {
  this.log.warn(`Unable to connect to OpenRGB SDK server at ${serverHost}:${serverPort}`);
  return 1;
}

let controllerCount = 0;

try {
  controllerCount = await client.getControllerCount(); // *** Crashes here ***
} catch (err) {
  this.log.warn(`Unable to enumerate RGB devices on OpenRGB SDK server at ${serverHost}:${serverPort}`);
}
Mola19 commented 2 years ago

Give me some time. This seems to need a deeper rework of the error handling

Mola19 commented 2 years ago

Okay i think i have a fix. Could you copy client.js from my repo to your /node_modules/openrgb-sdk/src/ folder

DallasHoff commented 2 years ago

That looks to be working correctly. Nice work. You can go ahead and release that patch, and I'll bump my plugin to use 0.5.1.

Mola19 commented 2 years ago

done

DallasHoff commented 2 years ago

Great! @arturoovf if you could update the plugin to version 1.2.3 and confirm everything is working for you, I'll close out this issue.

arturoovf commented 2 years ago

Looks good!! Thank you both so much!

DallasHoff commented 2 years ago

And thank you for taking the time to report the issue you had.