fix(api-graphql): trigger WebSocket reconnection on auth errors - #14569
Merged
bobbor merged 3 commits intoMar 23, 2026
Conversation
3 tasks
anivar
force-pushed
the
fix/datastore-sync-processor-retry-12954
branch
from
March 7, 2026 13:07
c7e92eb to
a5e1fbb
Compare
🦋 Changeset detectedLatest commit: 31df4fd The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Detect authentication errors (UnauthorizedException, NotAuthorizedException, Token expired) in subscription error responses using exact errorType matching and close the WebSocket to trigger reconnection with fresh tokens. Handles both EVENT_SUBSCRIBE_ERROR (structured errors array) and GQL_ERROR (payload errors) message types. The socket close fires the existing CONNECTION_CLOSED → ConnectionDisrupted → ReconnectionMonitor flow, so no changes needed in DataStore's disconnectionHandler. Fixes aws-amplify#12954
anivar
force-pushed
the
fix/datastore-sync-processor-retry-12954
branch
from
March 7, 2026 13:50
a5e1fbb to
9377435
Compare
Contributor
Author
|
This PR addresses the root cause described in #14587 (OIDC subscription UnauthorizedException) — WebSocket auth errors during token expiry now trigger proper reconnection instead of silently dropping subscriptions. |
3 tasks
bobbor
approved these changes
Mar 12, 2026
bobbor
left a comment
Member
There was a problem hiding this comment.
thanks for the contribution. LGTM
osama-rizk
approved these changes
Mar 13, 2026
This was referenced Mar 23, 2026
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.
Description of changes
After extended idle periods or device sleep/wake cycles (~12-24h), WebSocket subscriptions receive auth errors when tokens expire but nothing triggers reconnection — subscriptions silently die while the app reports everything is connected.
Fix: Detect auth errors in the WebSocket provider's subscription error handler using exact
errorTypematching and close the socket. The existingonclose→_errorDisconnect(CONNECTION_CLOSED)→ConnectionStateMonitor→ReconnectionMonitorflow then reconnects with fresh tokens automatically.What changed:
AWSWebSocketProvider._handleIncomingSubscriptionMessage()for bothEVENT_SUBSCRIBE_ERRORandGQL_ERRORmessage typesUnauthorizedException,Unauthorized,NotAuthorizedExceptionToken expiredin error message fieldCONNECTION_CLOSEDwhich DataStore'sdisconnectionHandlerhandlesWhat was removed vs original PR:
"401"/"403"substring matching (false positive risk — would match modelIds like"item-4013")disconnectionHandler(redundant — WebSocket close already triggersCONNECTION_CLOSED)Issue #, if available
Fixes #12954
Description of how you validated changes
Checklist
yarn testpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.