Skip to content

Commit 280d54f

Browse files
authored
fix: ignore dial request when one is in progress (libp2p#283)
1 parent 06fd7fc commit 280d54f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/connection/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class ConnectionFSM extends BaseConnection {
145145
dial () {
146146
if (this.theirB58Id === this.ourPeerInfo.id.toB58String()) {
147147
return this.emit('error', Errors.DIAL_SELF())
148+
} else if (this.getState() === 'DIALING') {
149+
return this.log('attempted to dial while already dialing, ignoring')
148150
}
149151

150152
this._state('dial')

test/connection.node.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ describe('ConnectionFSM', () => {
137137
connection.dial()
138138
})
139139

140+
it('should ignore concurrent dials', () => {
141+
const connection = new ConnectionFSM({
142+
_switch: dialerSwitch,
143+
peerInfo: listenerSwitch._peerInfo
144+
})
145+
146+
const stub = sinon.stub(connection, '_onDialing')
147+
148+
connection.dial()
149+
connection.dial()
150+
151+
expect(stub.callCount).to.equal(1)
152+
})
153+
140154
it('should be able to encrypt a basic connection', (done) => {
141155
const connection = new ConnectionFSM({
142156
_switch: dialerSwitch,

0 commit comments

Comments
 (0)