Skip to content

can not auto-reconnect聽#133

Description

@AaronJan

Describe the issue

First of all, great project! 馃憤

When client connected to a server, force exit the server and restart a new server, then the client seems to entered an infinity loop, it can never do a successful handshake with the new server, just keep reconnecting.

and when this happening, the client leak the NodeMessage for handshake as an message event, so I keep getting a handshake message on every reconnecting.

Code or steps to reproduce

Server:

import { Server } from 'veza';

async function main(): Promise<void> {
  const name = 'my_server';
  console.log('name', name);

  const server = new Server(name);
  await server.listen({
    host: '127.0.0.1',
    port: 11122,
  });
  setInterval(async () => {
    console.log('broadcast!', server.sockets.size);
    await server.broadcast({ hello: 'world' });
  }, 2000);
}

main();

Client:

import { Client } from 'veza';

async function main(): Promise<void> {
  const name = 'my_client';
  console.log('name', name);

  const client = new Client(name);
  client.on('message', message => {
    // Shouldn't get a handshake message in here.
    console.log('message!', message);
    message.reply({ world: 'hello' });
  });
  await client.connectTo({
    host: '127.0.0.1',
    port: 11122,
  });
}

main();
  1. start server
  2. start client
  3. ctrl+c stop the server
  4. restart server

Expected and actual behavior

  • The client should reconnect with the new server
  • The client's message event should be emitted with a handshake message

Further details

  • node.js version: 13.2.0
  • veza version: 1.1.0
  • I have tested the issue on latest master. Commit hash:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions