-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(api-graphql): add WebSocket health monitoring and manual reconnection #14563
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
Open
anivar
wants to merge
2
commits into
aws-amplify:main
Choose a base branch
from
anivar:feat/websocket-health-monitoring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
bobbor
requested changes
Oct 30, 2025
Member
bobbor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening the PR.
Please take a look at the comments
packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Outdated
Show resolved
Hide resolved
packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Outdated
Show resolved
Hide resolved
packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Outdated
Show resolved
Hide resolved
packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Outdated
Show resolved
Hide resolved
packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Outdated
Show resolved
Hide resolved
packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Outdated
Show resolved
Hide resolved
packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Outdated
Show resolved
Hide resolved
packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Outdated
Show resolved
Hide resolved
packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Outdated
Show resolved
Hide resolved
packages/api-graphql/src/Providers/AWSWebSocketProvider/index.ts
Outdated
Show resolved
Hide resolved
1eb4414 to
044fc3c
Compare
…ction - Add getConnectionHealth() method for current connection state - Add getPersistentConnectionHealth() for cross-session health tracking - Add isConnected() for quick connection status check - Add reconnect() for manual WebSocket reconnection - Implement persistent keep-alive tracking using AsyncStorage/localStorage - Use 65-second threshold for health monitoring - Track keep-alive timestamps for connection health assessment Fixes aws-amplify#9749, aws-amplify#4459, aws-amplify#5403, aws-amplify#7057
d1cf448 to
9c832cd
Compare
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.
This PR addresses several long-standing user requests for better WebSocket connection control in the GraphQL API client. Users have reported issues with WebSocket connections not automatically reconnecting after network interruptions and lacking visibility into connection health status ( Fixes #9749, #4459, #5403, #7057).
The implementation enhances the existing AWSWebSocketProvider class with four new methods that leverage the existing ConnectionStateMonitor infrastructure and keep-alive tracking. These methods provide both real-time health monitoring and manual connection control that users have been requesting.
Enhanced WebSocket Provider Methods
getConnectionHealth()- Returns current health state using in-memory keep-alive trackinggetPersistentConnectionHealth()- Returns health state with cross-session persistence via AsyncStorage/localStorageisConnected()- Checks if WebSocket.readyState === OPEN for immediate connection statusreconnect()/disconnect()- Manual connection control for user-triggered reconnection scenariosTechnical Implementation
The health monitoring uses the existing 65-second keep-alive threshold (DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT) already established in the AppSync WebSocket protocol. A WebSocket is considered healthy when three conditions are met: connection state is Connected, a keep-alive was received within 65 seconds, and the underlying WebSocket readyState is OPEN.
For persistence, the implementation uses a platform-safe approach with AsyncStorage for React Native and localStorage fallback for web platforms. Keep-alive timestamps are stored at 'AWS_AMPLIFY_LAST_KEEP_ALIVE' to avoid key collisions. When storage is unavailable, the feature gracefully degrades to in-memory tracking only.
All changes are backward compatible with no breaking changes to existing functionality.