Fix InvalidSessionException treated as permanent auth failure - #273
Closed
arpena wants to merge 1 commit into
Closed
Fix InvalidSessionException treated as permanent auth failure#273arpena wants to merge 1 commit into
arpena wants to merge 1 commit into
Conversation
InvalidSessionException inherits from UnauthorizedException, so it was being caught by the (AuthenticationException, UnauthorizedException) handler and raising ConfigEntryAuthFailed. This caused the integration to permanently stop polling and mark all entities as unavailable. InvalidSessionException is a transient error that occurs when the router invalidates the session (e.g., due to a concurrent login from the web interface). It should be treated as a retryable UpdateFailed so the integration recovers on the next polling cycle.
Owner
|
Thanks @arpena! We might want to fix this in the underlying library, what do you think? It seems that this is a transient error indeed, not an authentication error. |
Contributor
Author
|
Hi @iMicknl ! You are saying that we should change |
Owner
|
Yes! |
Contributor
Author
|
Closing in favor of fixing this at the library level: iMicknl/python-sagemcom-api#520 The root cause is that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
InvalidSessionExceptioninherits fromUnauthorizedException, so it was being caught by the(AuthenticationException, UnauthorizedException)handler which raisesConfigEntryAuthFailed. This permanently disables the integration and marks all entities asunavailable, requiring user re-authentication.Problem
When the router invalidates a session (e.g., due to a concurren login to the web interface using the same client IP as the Home Assistant server), the integration receives
XMO_INVALID_SESSION_ERR. This is a transient condition, not a credentials problem. However, due to the exception hierarchy (InvalidSessionException→UnauthorizedException), it was treated as a permanent auth failure.Fix
Catch
InvalidSessionExceptionexplicitly before theUnauthorizedExceptionhandler and raiseUpdateFailedinstead ofConfigEntryAuthFailed. This allows the coordinator to retry on the next polling cycle and recover automatically.Testing
Reproduced the issue by logging into the router web interface during a poll cycle. Before the fix, the integration died permanently. After the fix, it logs a warning and recovers on the next poll.