senecajs / seneca-transport

Seneca micro-services message transport over TCP and HTTP.
MIT License
63 stars 45 forks source link

Reconnect messages duplication #114

Closed dgonzalez closed 5 years ago

dgonzalez commented 8 years ago

This issue is related to #91.

Description

When using tcp as transport, if the client is up and the sever restarts all the messages are repeated.

The code to reproduce it is the following:

client.js

'use strict';

var seneca = require('seneca');

var service = seneca();

service.client({
    type: 'tcp',
    port: 12345,
    host: '0.0.0.0',
    pin: 'role:foo'
});

service.act({
    role: 'foo',
    cmd: 'bar',
    name: 'one',
}, function(err, res) {
    console.log(res, Date.now());
});

service.act({
    role: 'foo',
    cmd: 'bar',
    name: 'two',
}, function(err, res) {
    console.log(res, Date.now());
});

server.js

var seneca = require('seneca');

var service = seneca();

service.add({
    role: 'foo',
    cmd: 'bar'
}, function(args, cb) {
    console.log(args.name, Date.now(), args.meta$.id);
    cb(null, { test:123, name: args.name });
} )

service.listen({
    type: 'tcp',
    port: 12345,
    host: '0.0.0.0'
});

Run server.js in one terminal and client.js in another. If server.js gets restarted (ctrl-c and relaunch).

It does not happen with http transport but the behaviour is different: http disconnects as soon as the last act is sent whereas tcp keeps the connection alive preventing client.js to terminate.

As far as I can see, everything points to these lines (./lib/tcp.js):

 stream
          .pipe(parser)
          .pipe(msger)
          .pipe(stringifier)
          .pipe(stream)

If I read from the stream, all the messages are in there which suggests the client sending messages again as the server has restarted (lost the state).

This issue groups https://github.com/senecajs/seneca-transport/issues/91 and https://github.com/senecajs/seneca/issues/437.

combsco commented 8 years ago

I've recently experienced the same bug. If I bring down the service using seneca-transport tcp.

Client disconnects and does it's reconnect attempts. On successful reconnect the client is replaying the last action that was sent to this service.

mcdonnelldean commented 8 years ago

@combsco Yes, it is a known bug. We are going to rewrite the TCP driver soon enough.

mauliksoneji commented 7 years ago

I am experiencing the same issue as @combsco . Any updates on the issue, @mcdonnelldean ?

wzrdtales commented 6 years ago

@dgonzalez Is there any work from your side done on this? Since I do work on a new transport I would love to see if I could incorporate some of your thoughts.

computerex commented 6 years ago

So looks like this isn't getting any attention. This has been open for like 2 years now.