veza icon indicating copy to clipboard operation
veza copied to clipboard

can not auto-reconnect

Open AaronJan opened this issue 5 years ago • 2 comments

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:

AaronJan avatar Jan 17 '20 08:01 AaronJan

It's possible the behaviour of Node.js's net module changed with v13, I'll have to check, and while I'm at it, check why Dependabot's PRs are red.

But yes, your expected behaviour is also the one I expected, I believe I have a test just for that: https://github.com/kyranet/veza/blob/82a5765b74ca070ba2803d06f4ab6fb0d4cf5076/test/handshake.test.ts#L240-L294

Also, what happens if you only pass a port to connectTo and serve? server.listen(11122); and client.connectTo(11122); for instance.

kyranet avatar Jan 17 '20 13:01 kyranet

It's possible the behaviour of Node.js's net module changed with v13, I'll have to check, and while I'm at it, check why Dependabot's PRs are red.

But yes, your expected behaviour is also the one I expected, I believe I have a test just for that:

https://github.com/kyranet/veza/blob/82a5765b74ca070ba2803d06f4ab6fb0d4cf5076/test/handshake.test.ts#L240-L294

Also, what happens if you only pass a port to connectTo and serve? server.listen(11122); and client.connectTo(11122); for instance.

Thank you for the quick reply!

I tested it by only pass a port to both server and client, it didn't work, still the same.

AaronJan avatar Jan 17 '20 14:01 AaronJan