Skip to content

Commit 843ad67

Browse files
committed
Fix sending reset
1 parent 78eedcc commit 843ad67

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

packages/bolt-connection/src/bolt/bolt-protocol-v1.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ export default class BoltProtocol {
376376
return this._lastMessageSignature === 0x01
377377
}
378378

379+
isLastMessageReset () {
380+
return this._lastMessageSignature === 0x0f
381+
}
382+
379383
/**
380384
* Notifies faltal erros to the observers and mark the protocol in the fatal error state.
381385
* @param {Error} error The error

packages/bolt-connection/src/connection/connection-channel.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,22 @@ export default class ChannelConnection extends Connection {
341341
}
342342

343343
_reset(observer) {
344-
this._resetObservers.push(observer)
345344
if (this._reseting) {
345+
if (!this._protocol.isLastMessageReset()) {
346+
this._protocol.reset({
347+
onError: error => {
348+
observer.onError(error)
349+
}, onComplete: () => {
350+
observer.onComplete()
351+
}
352+
})
353+
} else {
354+
this._resetObservers.push(observer)
355+
}
346356
return
347357
}
358+
359+
this._resetObservers.push(observer)
348360
this._reseting = true
349361

350362
const notifyFinish = (notify) => {

packages/bolt-connection/test/connection/connection-channel.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ describe('ChannelConnection', () => {
269269

270270
const protocol = {
271271
reset: jest.fn(),
272-
resetFailure: jest.fn()
272+
resetFailure: jest.fn(),
273+
isLastMessageReset: jest.fn(() => true)
273274
}
274275
const protocolSupplier = () => protocol
275276
const connection = spyOnConnectionChannel({ channel, protocolSupplier })
@@ -454,7 +455,8 @@ describe('ChannelConnection', () => {
454455
reset: jest.fn(observer => {
455456
setTimeout(() => observer.onComplete(), 100)
456457
}),
457-
resetFailure: jest.fn()
458+
resetFailure: jest.fn(),
459+
isLastMessageReset: jest.fn(() => true)
458460
}
459461
const protocolSupplier = () => protocol
460462
const connection = spyOnConnectionChannel({ channel, protocolSupplier })

0 commit comments

Comments
 (0)