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

NATS Websocket connection in the browser randomly gets closed. Ping sent after 1 minute even with pingInterval: 25seconds. #258

Open
tehseensajjad-sys opened this issue Jan 8, 2025 · 0 comments
Labels
defect Suspected defect such as a bug or regression

Comments

@tehseensajjad-sys
Copy link

tehseensajjad-sys commented Jan 8, 2025

Observed behavior

Our frontend application is moving to replace inhouse websocket server with NATS Websocket. All seems good except the nats websocket connection is randomly getting closed and a new one is created. In firefox the error code mentioned is Closed 1006. pingInterval is set to 25 seconds to keep the connection from idling but i noticed in some instances a ping is sent after a whole minute, thus browser closes the connection.

You can notice the last ping sent after 60 second after which the connection is closed by the browser, in this image of the socket pings

Expected behavior

Nats websocket connection should remain open and pings should be sent consistently

Server and client version

nats-server: v2.10.22
nats.ws: v1.29.2
Browsers tested: Chrome, Firefox, Safari

Host environment

3 node nats cluster runs in Kubernetes behind an AWS NLB.
TLS is terminated by APISIX gateway route.
Socket endpoint is wss://
Client runs in the browser.

Steps to reproduce

import {
  connect,
} from "nats.ws";

const natsConnection = await connect({ 
  servers: WSS_SOCKET_URL,
  name: `web-client`,
  pingInterval: 25000,
});

natsConnection.closed()
  .then((err) => {
    console.log(
      `connection closed ${err ? " with error: " + err.message : ""}`,
    );
  });
@tehseensajjad-sys tehseensajjad-sys added the defect Suspected defect such as a bug or regression label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Suspected defect such as a bug or regression
Projects
None yet
Development

No branches or pull requests

1 participant