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

Websocket connection does not reconnect #210

Open
tylerschoppe opened this issue Mar 3, 2025 · 0 comments
Open

Websocket connection does not reconnect #210

tylerschoppe opened this issue Mar 3, 2025 · 0 comments

Comments

@tylerschoppe
Copy link

Observed behavior

When using the following websocket connection config, if the server is killed and then restarted the connection is not restored.

    const connectionPromise = wsconnect({
      debug: true,
      servers: ['ws://localhost:8443'],
      timeout: timeoutMs,
      reconnect: true,
      reconnectTimeWait: reconnectTimeWaitMs,
      maxReconnectAttempts,
    });

While the same configuration using the node transport does reconnect.

    const connectionPromise = connect({
      debug: true,
      servers: ['nats://localhost:4222'],
      timeout: timeoutMs,
      reconnect: true,
      reconnectTimeWait: reconnectTimeWaitMs,
      maxReconnectAttempts,
    });

It appears based on logging server status the websocket issues a reconnect attempt once and then hangs where as the node transport with the same configuration is retrying

status:  { type: 'disconnect', server: 'localhost:8443' }
status:  { type: 'reconnecting' }
status:  { type: 'disconnect', server: 'localhost:4222' }
resolve localhost = 127.0.0.1,::1
status:  { type: 'reconnecting' }
status:  { type: 'reconnecting' }
...
status:  { type: 'update', added: [], deleted: [] }
status:  { type: 'reconnect', server: 'localhost:4222' }

It's worth noting I did observe the websocket connection reconnect once if I killed and restarted my server very quickly.

Expected behavior

As both transports accept the same argument set ConnectionOptions from nats-core I would expect their behaviors to be identical.

Server and client version

Server version: 2.10.21
NATS core version: 3.0.0-51

Host environment

No response

Steps to reproduce

Using node 22, connect using the two examples provided in Observed Behavior. Run the following code with your connection, killing your server and restarting after a few seconds, the websocket connection will not be restored while the node transport connection will be.

  setInterval(() => {
    console.log('publishing message...');
    nc.publish('test', 'hello');
  }, 5000);
  for await (const s of nc.status()) {
    console.log('status: ', s);
  }
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