dgreif / ring

Unofficial packages for Ring Doorbells, Cameras, Alarm System, and Smart Lighting
MIT License
1.21k stars 163 forks source link

Push Receiver stops getting notifications #934

Closed djm181 closed 2 years ago

djm181 commented 2 years ago

Bug Report

Describe the Bug

A long-running connection to the Ring API stops receiving notifications through the push receiver. Once the account is in this state, recycling the connection (or even the process) has no effect - the push receiver still receives no dings.

To Reproduce

Steps to reproduce the behavior:

Expected behavior

Dings should come through forever.

Screenshots/Logs

Additional context

The only workaround I've found once in this state is to remove the Authorized Devices from the account and generate a fresh refresh token. Somehow it appears the token is getting "tainted" with Ring and not receiving push notifications any more. I'm guessing this is something to do with the credentials for FCM not being updated correctly, but it's not clear to me what the issue here would be.

Environment

dgreif commented 2 years ago

@djm181 i'm not able to reproduce this issue. I've had homebridge running for 6 days and it's still getting push notifications šŸ˜•. Have you seen this same behavior since first reporting?

tsightler commented 2 years ago

I've also not been able to reproduce this. I've been testing the push notifications in the ring-mqtt codebase since @dgreif first introduced them during v10-beta and, so far, I've not seen push notifications fail and I've definitely had them running, for 10+ days in some cases, on both my production and development instances. I've also definitely not had to generate any new tokens.

Just in case, are you definitely monitoring onRefreshTokenUpdated and saving new tokens as they are renewed? Regardless, I'll continue to monitor my systems closely for this behavior and report here if I see it or have other ring-mqtt users report it.

djm181 commented 2 years ago

I haven't seen this behavior since reporting this but I made changes to my app to try and get around it. Specifically I changed the systemId that I pass in the options so that it changes each time. This certainly addresses the problem, but it pollutes the account with myriad authorized devices.

I do monitor onRefreshTokenUpdated and save the new tokens. The PushReceiver doesn't seem to care about this part though. I will note that calls like getCameras or getCameraEvents continue to work the whole time, even when my push notifications have stalled - so I know the refresh token is valid.

Because my use case can result in new cameras being shared from time to time, I do have a periodic job to refresh the list of cameras, which is admittedly a bit of a hack:

// conn is my RingApi instance
conn.disconnect();
conn["locationsPromise"] = conn.fetchAndBuildLocations();

I don't think I see any way for this to be causing the issue I'm seeing though, especially since I experience it across restarts of the app.

I'll make the systemId stable again and see if the problem reoccurs.

djm181 commented 2 years ago

Hmm, one other thing I think is a little out of the ordinary for me - I have previously use the same systemId for logging into two different ring accounts simultaneously. Different credentials and refresh tokens obviously, but I wonder if the ring system has any issue with this from a sessions standpoint.

tsightler commented 2 years ago

Interesting, it's something worth investigating. I can at least see how the Ring backend system might not expect this to be possible and it might cause unexplained behavior.

I continue to have no issues with my instances and, so far, no users that have upgraded to ring-mqtt v5 have reported this issue, but that of course does not mean it doesn't exist as it's only been about a week since it was released. My current prod/test instances have currently been up for 5 days, so I'll keep monitoring.

dgreif commented 2 years ago

@djm181 that definitely seems like a scenario that would cause problems. I believe the hardware_id (generated from systemId) is intended to be unique, and is the id used to update the push notification token. Sharing that id between two accounts could definitely cause some odd problems in Rings system. Since we haven't had any other reports, I think it's safe to assume that's the root issue here. Thanks for reporting it though, keep the info coming šŸ˜„