@@ -119,7 +119,7 @@ class BandwidthMeasurementEngine {
119119
120120 // Public methods
121121 pause ( ) {
122- this . #cancelCurrentMeasurement( ) ;
122+ this . #cancelCurrentMeasurement( `pause()` ) ;
123123 this . #setRunning( false ) ;
124124 }
125125
@@ -157,6 +157,10 @@ class BandwidthMeasurementEngine {
157157 this . #running = running ;
158158 setTimeout ( ( ) => this . #onRunningChange( this . #running) ) ;
159159 }
160+
161+ if ( ! running ) {
162+ this . #currentAbortController?. abort ( 'setRunning(false)' ) ;
163+ }
160164 }
161165
162166 #saveMeasurementResults( measIdx , measTiming ) {
@@ -271,17 +275,19 @@ class BandwidthMeasurementEngine {
271275 this . #fetchOptions
272276 ) ;
273277
274- // AbortController and timeout is shared between all retries
275278 if ( this . #retries === 0 ) {
279+ // abort existing abort controller
280+ this . #currentAbortController?. abort ( 'restarting engine' ) ;
281+
282+ // create new abort controller
276283 this . #currentAbortController = new AbortController ( ) ;
277284 if ( this . abortRequestDuration ) {
278285 const abortTimeout = setTimeout ( ( ) => {
279- this . #cancelCurrentMeasurement( ) ;
286+ const errorMessage = `${ isDown ? 'Download' : 'Upload' } measurement of ${ numBytes } bytes aborted. Measurement exceeded bandwidthAbortRequestDuration (${ this . abortRequestDuration } ms)` ;
287+ this . #cancelCurrentMeasurement( errorMessage ) ;
280288 this . #retries = 0 ;
281289 this . #setRunning( false ) ;
282- this . #onConnectionError(
283- `${ isDown ? 'Download' : 'Upload' } measurement of ${ numBytes } bytes aborted. Measurement exceeded bandwidthAbortRequestDuration (${ this . abortRequestDuration } ms)`
284- ) ;
290+ this . #onConnectionError( errorMessage ) ;
285291 } , this . abortRequestDuration ) ;
286292 this . #currentAbortController. signal . addEventListener ( 'abort' , ( ) =>
287293 clearTimeout ( abortTimeout )
@@ -392,8 +398,10 @@ class BandwidthMeasurementEngine {
392398 } ) ;
393399 }
394400
395- #cancelCurrentMeasurement( ) {
396- this . #currentAbortController. abort ( ) ;
401+ #cancelCurrentMeasurement( reason ) {
402+ this . #currentAbortController?. abort (
403+ reason || `aborted with no reason provided`
404+ ) ;
397405 }
398406}
399407
0 commit comments