Skip to content

Commit 0434221

Browse files
committed
Fixes per review coderabbit
1 parent 8c40cfe commit 0434221

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/js/msp.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,8 @@ const MSP = {
384384

385385
const requestObj = this._createRequestObject(code, bufferOut, callback_msp, doCallbackOnError);
386386

387-
// Set up timeout only for new requests
388-
if (!isDuplicateRequest) {
389-
this._setupTimeout(requestObj, bufferOut);
390-
}
387+
// Always set up timeout for all requests to ensure cleanup
388+
this._setupTimeout(requestObj, bufferOut);
391389

392390
this.callbacks.push(requestObj);
393391

@@ -443,11 +441,17 @@ const MSP = {
443441
`QUEUE: ${this.callbacks.length} (${this.callbacks.map((e) => e.code)})`,
444442
);
445443

444+
// Clear the existing timer before retry
445+
clearTimeout(requestObj.timer);
446+
446447
serial.send(bufferOut, (_sendInfo) => {
447448
requestObj.stop = performance.now();
448449
const executionTime = Math.round(requestObj.stop - requestObj.start);
449450
this.timeout = Math.max(this.MIN_TIMEOUT, Math.min(executionTime, this.MAX_TIMEOUT));
450451
});
452+
453+
// Re-arm the timeout for retry attempts
454+
this._setupTimeout(requestObj, bufferOut);
451455
},
452456

453457
_shouldSendMessage(data, isDuplicateRequest) {

0 commit comments

Comments
 (0)