@@ -430,14 +430,37 @@ const MSP = {
430
430
// Clear the existing timer before retry
431
431
clearTimeout ( requestObj . timer ) ;
432
432
433
- serial . send ( bufferOut , ( _sendInfo ) => {
434
- requestObj . stop = performance . now ( ) ;
435
- const executionTime = Math . round ( requestObj . stop - requestObj . start ) ;
436
- this . timeout = Math . max ( this . MIN_TIMEOUT , Math . min ( executionTime , this . MAX_TIMEOUT ) ) ;
433
+ serial . send ( bufferOut , ( sendInfo ) => {
434
+ if ( sendInfo . bytesSent === bufferOut . byteLength ) {
435
+ // Successfully sent retry
436
+ requestObj . stop = performance . now ( ) ;
437
+ const executionTime = Math . round ( requestObj . stop - requestObj . start ) ;
438
+ this . timeout = Math . max ( this . MIN_TIMEOUT , Math . min ( executionTime , this . MAX_TIMEOUT ) ) ;
439
+
440
+ // Re-arm the timeout for retry attempts
441
+ this . _setupTimeout ( requestObj , bufferOut ) ;
442
+ } else {
443
+ // Failed to send retry - remove request and handle error
444
+ console . error (
445
+ `MSP: Failed to send retry for request ${ requestObj . code } : ` +
446
+ `sent ${ sendInfo . bytesSent } /${ bufferOut . byteLength } bytes` ,
447
+ ) ;
448
+
449
+ this . _removeRequestFromCallbacks ( requestObj ) ;
450
+
451
+ // Call error callback if available
452
+ if ( requestObj . callbackOnError && requestObj . callback ) {
453
+ requestObj . callback ( ) ;
454
+ }
455
+ }
437
456
} ) ;
457
+ } ,
438
458
439
- // Re-arm the timeout for retry attempts
440
- this . _setupTimeout ( requestObj , bufferOut ) ;
459
+ _removeRequestFromCallbacks ( requestObj ) {
460
+ const index = this . callbacks . indexOf ( requestObj ) ;
461
+ if ( index > - 1 ) {
462
+ this . callbacks . splice ( index , 1 ) ;
463
+ }
441
464
} ,
442
465
443
466
/**
0 commit comments