-
Notifications
You must be signed in to change notification settings - Fork 761
chore: realtime api improvements #1340
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
Conversation
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.
Dependency update and WebSocket connection handling improvements with added error listener and open state check.
Skipped files
package-lock.json
: Skipped file pattern
"@cfworker/json-schema": "^4.0.3", | ||
"@hono/node-server": "^1.3.3", | ||
"@hono/node-ws": "^1.0.4", | ||
"@hono/node-ws": "^1.2.0", |
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.
📦 Dependency Issue
Issue: Updated @hono/node-ws from 1.0.4 to 1.2.0
Fix: Verify compatibility with existing WebSocket usage
Impact: Ensures latest bug fixes and features
"@hono/node-ws": "^1.2.0", | |
"@hono/node-ws": "^1.2.0", |
// wait for the upstream websocket to be open | ||
const checkWebSocketOpen = new Promise((resolve) => { | ||
outgoingWebSocket.addEventListener('open', () => { | ||
resolve(true); | ||
}); | ||
}); | ||
|
||
await checkWebSocketOpen; |
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.
🛠️ Code Refactor
Issue: Added promise to wait for upstream WebSocket to be open
Fix: Ensures proper connection sequence before proceeding
Impact: Improves reliability of WebSocket connections
// wait for the upstream websocket to be open | |
const checkWebSocketOpen = new Promise((resolve) => { | |
outgoingWebSocket.addEventListener('open', () => { | |
resolve(true); | |
}); | |
}); | |
await checkWebSocketOpen; | |
// wait for the upstream websocket to be open | |
const checkWebSocketOpen = new Promise((resolve) => { | |
outgoingWebSocket.addEventListener('open', () => { | |
resolve(true); | |
}); | |
}); | |
await checkWebSocketOpen; |
const errorListener = (event: ErrorEvent) => { | ||
console.error('outgoingWebSocket error: ', event); | ||
server?.close(); | ||
}; |
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.
🛠️ Code Refactor
Issue: Added error listener for outgoing WebSocket and proper cleanup
Fix: Centralizes error handling and removes listener on close
Impact: Prevents memory leaks and improves error handling
const errorListener = (event: ErrorEvent) => { | |
console.error('outgoingWebSocket error: ', event); | |
server?.close(); | |
}; | |
const errorListener = (event: ErrorEvent) => { | |
console.error('outgoingWebSocket error: ', event); | |
server?.close(); | |
}; | |
server.addEventListener('error', errorListener); |
console.error('serverWebSocket error: ', event); | ||
outgoingWebSocket?.close(); | ||
}); | ||
server.addEventListener('error', errorListener); |
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.
🛠️ Code Refactor
Issue: Removed duplicate error listener and centralized it
Fix: Avoids duplicate error handling logic
Impact: Reduces code duplication and improves maintainability
server.addEventListener('error', errorListener); | |
server.addEventListener('error', errorListener); |
Description
Motivation
Type of Change
How Has This Been Tested?
Screenshots (if applicable)
Checklist
Related Issues