-
Previously when using const ws = new WebSocketLink({
url: `${apiEndpoint.replace('http', 'ws')}/graphql`,
keepAlive: 30_000,
retryAttempts: Infinity,
retryWait: async function waitForServerHealthyBeforeRetry() {
await new Promise((resolve) => setTimeout(resolve, 1000 + Math.random() * 3000));
},
on: {
opened: (socket) => (activeSocket = socket),
ping: (received) => {
if (!received) {
pingSentAt = Date.now();
timedOut = setTimeout(() => {
if (activeSocket.readyState === WebSocket.OPEN) {
activeSocket.close(4408, 'Request Timeout');
}
}, 5_000);
}
},
pong: (received) => {
if (received) {
latency = Date.now() - pingSentAt;
console.log(`${latency}ms`);
clearTimeout(timedOut);
}
},
},
}); Now if I restart my server, I'm seeing that it only seems to retry 3x before completely stopping and it's as though the retryAttempts is ignored entirely. Is there something special I need to do for handling ungraceful server shutdowns with retrying? If a user is on site and the server goes down, I'd like the site to basically come back alive whilst he's looking at it and not know that he needs to refresh. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The default Can you expand more on the close event? Close code and reason would be helpful. Furthermore, if the error is not a close event, it is probably a fatal error and they don't get retried by default. To control whether the error is fatal, you might consider using the |
Beta Was this translation helpful? Give feedback.
The default
retryWait
client option is using randomised exponential backoff, you should consider using the default instead. Custom retry strategy example from the readme is just in case you want to supply your own custom logic.Can you expand more on the close event? Close code and reason would be helpful.
Furthermore, if the error is not a close event, it is probably a fatal error and they don't get retried by default. To control whether the error is fatal, you might consider using the
isFatalConnectionProblem
client option.