From 280d54f74faabec81f6d7ab4d89922bacc25b228 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Tue, 23 Oct 2018 18:52:43 +0200 Subject: [PATCH] fix: ignore dial request when one is in progress (#283) --- src/connection/index.js | 2 ++ test/connection.node.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/connection/index.js b/src/connection/index.js index 01a6ec9c16..2f9316df58 100644 --- a/src/connection/index.js +++ b/src/connection/index.js @@ -145,6 +145,8 @@ class ConnectionFSM extends BaseConnection { dial () { if (this.theirB58Id === this.ourPeerInfo.id.toB58String()) { return this.emit('error', Errors.DIAL_SELF()) + } else if (this.getState() === 'DIALING') { + return this.log('attempted to dial while already dialing, ignoring') } this._state('dial') diff --git a/test/connection.node.js b/test/connection.node.js index 1e1d1009bd..6f528cd92b 100644 --- a/test/connection.node.js +++ b/test/connection.node.js @@ -137,6 +137,20 @@ describe('ConnectionFSM', () => { connection.dial() }) + it('should ignore concurrent dials', () => { + const connection = new ConnectionFSM({ + _switch: dialerSwitch, + peerInfo: listenerSwitch._peerInfo + }) + + const stub = sinon.stub(connection, '_onDialing') + + connection.dial() + connection.dial() + + expect(stub.callCount).to.equal(1) + }) + it('should be able to encrypt a basic connection', (done) => { const connection = new ConnectionFSM({ _switch: dialerSwitch,