Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock in Websocket connection if token refresh fails #153

Closed
SchmalzM opened this issue Nov 25, 2023 · 2 comments
Closed

Deadlock in Websocket connection if token refresh fails #153

SchmalzM opened this issue Nov 25, 2023 · 2 comments
Assignees
Labels
bug Something isn't working retest-needed

Comments

@SchmalzM
Copy link

Hi,
if there is a temporary problem in the network and refreshing the access token fails, the process to connect the websocket connection goes into an endless loop always using the expired token which fails.
The logs look like this:
[custom_components.mbapi2020.oauth] Start async_get_cached_token()
[custom_components.mbapi2020.oauth] custom_components.mbapi2020.oauth token expired -> start refresh
[custom_components.mbapi2020.oauth] Start async_refresh_access_token() with refresh_token
[custom_components.mbapi2020.oauth] ClientError requesting data from https://id.mercedes-benz.com/as/token.oauth2: Cannot connect to host id.mercedes-benz.com:443 ssl:True [Try again]
[custom_components.mbapi2020.websocket] Connecting to wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/ws
[custom_components.mbapi2020.websocket] Could not connect to wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/ws, retry in 10 seconds...
[custom_components.mbapi2020.websocket] Cannot connect to host websocket.emea-prod.mobilesdk.mercedes-benz.com:443 ssl:default [Try again]
[custom_components.mbapi2020.websocket] Connecting to wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/ws
[custom_components.mbapi2020.websocket] Could not connect to wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/ws, retry in 10 seconds...

This is because in async_get_cached_token a client error is ignored and the old token is returned. Afterwards the websocket async_connect enters an endless retry loop without ever refreshing updating the headers to use.

It seems like my network is not perfectly stable, so this happens from time to time and I have to restart the integration.

@ReneNulschDE ReneNulschDE self-assigned this Nov 25, 2023
@ReneNulschDE ReneNulschDE added the bug Something isn't working label Nov 25, 2023
@ReneNulschDE
Copy link
Owner

Thanks for reporting. Fixed with this commit

@SchmalzM
Copy link
Author

SchmalzM commented Dec 2, 2023

Seems to be fixed

@SchmalzM SchmalzM closed this as completed Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working retest-needed
Projects
None yet
Development

No branches or pull requests

2 participants