dgreif / homebridge-hatch-baby-rest

A homebridge plugin for Hatch Baby Rest night light
MIT License
74 stars 19 forks source link

Infinite Loops #23

Closed kenwdelong closed 4 years ago

kenwdelong commented 4 years ago

I work for Hatch, and I wanted to report some bugs that apparently are coming from your plugin.

You have one user that is stuck in an endless loop issuing requests to /public/v1/login every 5 seconds. Their client has issued almost 500,000 requests in the last 10 days! Interestingly, the logins are successful, not failure. I cannot see in the code where this error might be coming from, but I don't know about homebridge.

Ps, if you want assistance with the APIs, I can offer help, although it certainly looks like you've reverse engineered most of them!

dgreif commented 4 years ago

@kenwdelong thanks for reaching out! The current code will hit the /public/v1/login endpoint when it receives a 401 response from any endpoint, or if homebridge is restarted. See https://github.com/dgreif/homebridge-hatch-baby-rest/blob/master/src/rest-client.ts#L93-L96. Can you see if they are hitting service/app/restPlus/token/v1/fetch or service/app/restPlus/v1/fetch in their loop? If it is just restPlus/token/v1/fetch, then they are stuck in a loop in the code. If it is restPlus/token/v1/fetch and restPlus/v1/fetch both getting hammered, then the user is likely in a state where their homebridge server is constantly erroring and restarting. If the later is the case, then you will probably have to reach out to the user directly to have them see what's wrong.

I very much appreciate the offer for API assistance! I do have pretty much all that I need reverse engineered, but I would love to see any documentation you have for either the rest API or the bluetooth api. And please don't hesitate to reach out again if you see my plugin doing something that it shouldn't 😄

kenwdelong commented 4 years ago

Looks like it's only /public/v1/login. We have reached out to him and asked him to reboot his device!

We don't really have any API docs that are suitable for external consumption. Feel free to ping me if you need any clarifications, however.

dgreif commented 4 years ago

I double checked the code and if it is only /public/v1/login, then the user very well could be in a loop of some sort. If the request to log in fails due to network issues, it automatically tries again in 5 seconds. Sounds like the exact scenario you are seeing. I'll work on an update over the weekend that should be a bit more reliable. Please have the user reach out on this GitHub issue if they are able.

dgreif commented 4 years ago

@kenwdelong I released v2.0.4 which uses a different http client and logs a little more information when it gets into that 5 second retry loop. If the user is still having issues, you could have them update to that version and check their logs. I'm happy to help out any way that I can.