@@ -430,14 +430,37 @@ const MSP = {
430430 // Clear the existing timer before retry
431431 clearTimeout ( requestObj . timer ) ;
432432
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+ }
437456 } ) ;
457+ } ,
438458
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+ }
441464 } ,
442465
443466 /**
0 commit comments