Read timeout when refreshing token
cliffjao opened this issue · 11 comments
Every so often, I get a read timeout exception while refreshing the token:
HTTPSConnectionPool(host='api.ecobee.com', port=443): Read timed out. (read timeout=5)
If I attempt to refresh again, I get an invalid_grant error, which means I have to start auth all over again:
ecobee authorization error encountered for URL => https://api.ecobee.com/token?client_id=REDACTEDSDFSF&code=REDACTEDDFGDFG&grant_type=refresh_token
HTTP error code => 400
Error type => invalid_grant
Error description => The authorization grant, token or credentials are invalid, expired, revoked, do not match the redirection URI used in the authorization request, or was issued to another client.
Error URI => https://tools.ietf.org/html/rfc6749#section-5.2
Are there any workarounds here?
Also curious whether a longer read timeout might help here.
I think what is going on here is that you send a refresh tokens request to the server. The server performs the refresh and sends your app the response but your app timeouts out while reading the response. As a result the server is now expecting a new set of tokens which your app never received.
Any idea why you're getting the read timeout exception? Does your connection go down during that time? A longer timeout might help reduce the occurrence of such timeouts but would not be a foolproof solution.
That's my hunch as well... My first thought is that it's Ecobee's servers. My connection (Xfinity) is pretty stable and this app/script is running on a NAS box that's connected via Ethernet.
FWIW, I am seeing the same symptoms - only for me it is getting progressively more frequent (now every couple of days). My internet provider is Spectrum, and while I don't regard them as quite a reliable as Xfinity (I changed providers from one to the other moved house a few months ago) none of my other internet-facing apps are crashing or reporting problems. I too suspect that the problem is at the Ecobee end. If so, God help us when they go to the proposed much longer security keys!
It seems that increasing the read timeout can help. Here's one of my log events where it took about 8 seconds for refresh_tokens with timeout=30 to be successful:
2020-10-25 08:42:02.856716: Refreshing Ecobee tokens...
2020-10-25 08:42:10.479407: Refresh successful. Refresh expires on 2021-10-25 08:42:02.944213+00:00. Access expires on 2020-10-25 09:42:01.944213+00:00.
How/where do you modify the read timeout?
How/where do you modify the read timeout?
Every method of EcobeeService supports a timeout parameter. I have it setup with a default argument of 5 but if you pass in a different value then it'll override the default.
Here's an example
ecobee_service.refresh_tokens(timeout=10) # Override the timeout to 10s
Thanks! I had missed that.
For me, increasing the timeout limit to 15 seconds did not abolish the problem. I have now upped it to 30 seconds.
The timeout increase to 30 seconds seems to have worked. My app has stayed up since I sent my last message.
The timeout increase to 30 seconds seems to have worked. My app has stayed up since I sent my last message.
Glad that it is working fine now.