Merge pull request #57 from braydonf/bug/double-disconnect
Patched double disconnect bug.
This commit is contained in:
commit
438638c4ab
@ -170,7 +170,9 @@ Peer.prototype._addSocketEventHandlers = function() {
|
|||||||
|
|
||||||
Peer.prototype._onError = function(e) {
|
Peer.prototype._onError = function(e) {
|
||||||
this.emit('error', e);
|
this.emit('error', e);
|
||||||
this.disconnect();
|
if (this.status !== Peer.STATUS.DISCONNECTED) {
|
||||||
|
this.disconnect();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
20
test/peer.js
20
test/peer.js
@ -151,6 +151,26 @@ describe('Peer', function() {
|
|||||||
peer.socket.emit('error', error);
|
peer.socket.emit('error', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('will not disconnect twice on disconnect and error', function(done) {
|
||||||
|
var peer = new Peer({host: 'localhost'});
|
||||||
|
var socket = new EventEmitter();
|
||||||
|
socket.connect = sinon.stub();
|
||||||
|
socket.destroy = sinon.stub();
|
||||||
|
peer._getSocket = function() {
|
||||||
|
return socket;
|
||||||
|
};
|
||||||
|
peer.on('error', sinon.stub());
|
||||||
|
peer.connect();
|
||||||
|
var called = 0;
|
||||||
|
peer.on('disconnect', function() {
|
||||||
|
called++;
|
||||||
|
called.should.not.be.above(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
peer.disconnect();
|
||||||
|
peer.socket.emit('error', new Error('fake error'));
|
||||||
|
});
|
||||||
|
|
||||||
it('disconnect with max buffer length', function(done) {
|
it('disconnect with max buffer length', function(done) {
|
||||||
var peer = new Peer({host: 'localhost'});
|
var peer = new Peer({host: 'localhost'});
|
||||||
var socket = new EventEmitter();
|
var socket = new EventEmitter();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user