node-red / node-red-web-nodes

A collection of node-red nodes aimed at web services
Apache License 2.0
226 stars 156 forks source link

"Calendar in" node doesn't always trigger #214

Open battosai30 opened 6 years ago

battosai30 commented 6 years ago

Hi, I build a simple nodered script based on calendar to drive actions based on event programmend in a google calendar. As I observed that sometimes things didn't work as expected, I add a simple log to check if the problem was based on my script or only the calendar node, and it's the node. Sometimes, without any obvious reason, events are not triggered. I don't know if there is a link, but I get every hour a warning about tokens : [warn] [google-credentials:b990e830.25df58] trying to refresh token due to expiry

image

Any idea ?

Regards

elvetemedve commented 6 years ago

Hi @battosai30,

Well I experienced similar random failures in the past, that's why I changed the code to retry the failed token refresh multiple times while there is an exponential delay between two retries. See the PR https://github.com/node-red/node-red-web-nodes/pull/199.

However I still see problems with the calendar node. I get logs like this:

9 May 11:30:03 - [warn] [google-credentials:7aa57b80.2a8af4] 1. failed attempts. Waiting 100 ms before next attempt. 9 May 11:30:03 - [warn] [google-credentials:7aa57b80.2a8af4] 2. failed attempts. Waiting 900 ms before next attempt. 9 May 11:30:04 - [warn] [google-credentials:7aa57b80.2a8af4] 3. failed attempts. Waiting 8100 ms before next attempt. 9 May 11:30:12 - [warn] [google-credentials:7aa57b80.2a8af4] 4. failed attempts. Waiting 72900 ms before next attempt. 9 May 11:31:25 - [warn] [google-credentials:7aa57b80.2a8af4] 5. failed attempts. Waiting 73000 ms before next attempt. 9 May 11:32:38 - [warn] [google-credentials:7aa57b80.2a8af4] 6. failed attempts. Waiting 73000 ms before next attempt. 9 May 11:33:51 - [warn] [google-credentials:7aa57b80.2a8af4] 7. failed attempts. Waiting 73000 ms before next attempt. 9 May 11:35:04 - [warn] [google-credentials:7aa57b80.2a8af4] 8. failed attempts. Waiting 73000 ms before next attempt. 9 May 11:36:17 - [error] [google-credentials:7aa57b80.2a8af4] too many refresh attempts, giving up 9 May 11:36:17 - [warn] [google-credentials:7aa57b80.2a8af4] trying to refresh token due to expiry 9 May 11:36:17 - [error] [google calendar in:Calendar event starts] Error 401: {"error":{"errors":[{"domain":"global","reason":"authError","message":"Invalid Credentials","locationType":"header","location":"Authorization"}],"code":401,"message":"Invalid Credentials"}} 9 May 12:36:20 - [warn] [google-credentials:7aa57b80.2a8af4] trying to refresh token due to expiry 9 May 13:36:23 - [warn] [google-credentials:7aa57b80.2a8af4] trying to refresh token due to expiry

As you can see the first failed attempt happened at 11:30 and after 8 failures it stopped further attemps at 11:36. But one hour later at 12:36 the token refresh was successful. I doubt that Google API suffered service outage for more than 6 minutes. It's neither a problem at the Internet Service Provider, because the reason for the failure is HTTP 401 Unauthorized error which indicates that it got a response from the server, but the refresh token seems to be invalid. But one hour later it become valid again!? I think something is wrong with either in the code of the module or the network part of Node.js itself.

but I get every hour a warning about tokens

That's normal. Calendar events are detected by fetching the Google Calendar API from time to time. The API call requires an OAuth2 access token, but its lifetime is limited by Google to 1 hour. When the module detects the expiration, it tries to renew the token by sending the refresh token which has much longer lifetime (e.g. years). If the new access token arrives, then the module calls the original Google Calendar API with it and no interruption should happen. The error occurs during this renewal process.

Lenten1965 commented 5 years ago

I'm having the same problem... Makes a great app, unreliable and unusable...

DelukaDZ commented 5 years ago

This node only works for a hour after installing and then get the refresh token error. Left it alone to let it do its thing for a couple of days but still getting the same error