Skip to content
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

Connection does not close after the timeout expired #260

Open
denvudd opened this issue Jan 17, 2025 · 1 comment
Open

Connection does not close after the timeout expired #260

denvudd opened this issue Jan 17, 2025 · 1 comment

Comments

@denvudd
Copy link

denvudd commented Jan 17, 2025

Hello everyone! First of all, thank you for this library, saves me a ton of time.
So I tried to use the heartbeat feature. On version 4.11.1 I experienced that the "ping" message doesn't send therefore it just timeouts because there is no response from the server (because the server doesn't receive a "ping" message), so I downgraded to version 4.8.1 (#255) and it worked. But now after heartbeat timeouts and there are no responses from the server nothing happens. I expect a closing connection after heartbeat timeouts, am I missing something or do I understand the logic wrong?

This is my options with heartbeat:

shouldReconnect: (closeEvent) => {
  return (
    shouldConnect &&
    reconnectAttemptsRef.current < RECONNECT_INTERVALS.length
  );
},
reconnectAttempts: RECONNECT_INTERVALS.length,
reconnectInterval: (attemptNumber) => {
  reconnectAttemptsRef.current = attemptNumber + 1;
  setCurrentReconnectAttempt(attemptNumber + 1);

  return (
    RECONNECT_INTERVALS[attemptNumber] ||
    RECONNECT_INTERVALS[RECONNECT_INTERVALS.length - 1]
  );
},
 onClose: () => {
  console.log(
    `WebSocket closed. Attempt ${reconnectAttemptsRef.current} of ${RECONNECT_INTERVALS.length}`
  );

  if (restOptions?.onClose) {
    restOptions.onClose();
  }
},
 heartbeat: {
  message: JSON.stringify({ action: "ping", request_id: "0" }),
  returnMessage: JSON.stringify({
    errors: [],
    data: { message: "Pong!" },
    action: "ping",
    response_status: 200,
    request_id: "0",
  }),
  timeout: restOptions?.heartbeatTimeout || HEARTBEAT_TIMEOUT,
  interval: restOptions?.heartbeatInterval || HEARTBEAT_INTERVAL,
},

The "ping" message sends and even if there is no response from the server - it sends the next "ping" message and then just stops and does nothing.

Image

@denvudd
Copy link
Author

denvudd commented Jan 17, 2025

Also, I noticed that after the connection was restored (and "ping" messages were without responses) the WebSocket reconnected automatically, so I suppose it still closes the connection after heartbeat timeouts but maybe doesn't change the connection status. This is just an assumption anyway because I don't have a lot of experience with sockets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant