Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

On reconnect loses reference to net socket #51

Closed
nickpoorman opened this Issue · 0 comments

1 participant

@nickpoorman

After a reconnect() seaport loses the reference to the net socket, which makes it impossible to do a close().

I think what you want below on line 46 is:

c = net.connect.call(null, hubs[conIx].port, hubs[conIx].host);

not:

var c = net.connect.call(null, hubs[conIx].port, hubs[conIx].host);

https://github.com/substack/seaport/blob/master/index.js#L46

    var c = (function reconnect () {
        if (s.closed) return;

        var hubs = [ { port : port, host : host } ].concat(s.query('seaport'));
        if (hubs.length <= conIx) conIx = hubs.length - 1;
 ==>    c = net.connect.call(null, hubs[conIx].port, hubs[conIx].host);
        conIx = (conIx + 1) % hubs.length;

        var active = true;

        c.on('connect', s.emit.bind(s, 'connect'));

        c.on('end', onend);
        c.on('error', onend);
        c.on('close', onend);

        var stream = s.createStream();

        c.pipe(stream).pipe(c);

        stream.on('synced', s.emit.bind(s, 'synced'));

        return c;

        function onend () {
            if (s.closed) return;
            if (!active) return;
            active = false;
            stream.destroy();
            s.emit('disconnect');
            setTimeout(reconnect, 1000);
        }
    })();

    s.on('close', function () {
        if (c) c.end();
    });

    return s;
};
@nickpoorman nickpoorman referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@nickpoorman nickpoorman referenced this issue from a commit in nickpoorman/seaport
@nickpoorman nickpoorman fixes #51 ed35b15
@nickpoorman nickpoorman referenced this issue
Closed

fixes #51 #52

@substack substack closed this issue from a commit
@nickpoorman nickpoorman fixes #51 32ffdda
@substack substack closed this in 32ffdda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.