Skip to content

Commit 93c38f2

Browse files
committed
Improve process handling during pause and resume operations
1 parent 406d17a commit 93c38f2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/speed-test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ function process() {
117117

118118
const item = queue.pop()
119119

120-
// Skip if request already in flight
120+
// Skip if request already in flight - but keep this worker running
121121
if (callRecords[item.domain]) {
122+
// Put item back in queue and try another
123+
queue.unshift(item)
122124
return setTimeout(process, CONFIG.RETRY_DELAY_MS)
123125
}
124126

@@ -407,6 +409,13 @@ export const pause = () => {
407409
*/
408410
export const resume = () => {
409411
state.isPaused = false
412+
413+
// Clear any stale call records from before pause
414+
// This ensures workers don't skip requests thinking they're already in flight
415+
Object.keys(callRecords).forEach(domain => {
416+
delete callRecords[domain]
417+
})
418+
410419
pauseCallbacks.forEach(callback => {
411420
try {
412421
callback(false)
@@ -415,7 +424,7 @@ export const resume = () => {
415424
}
416425
})
417426

418-
// Restart workers
427+
// Restart full set of workers to ensure proper concurrency
419428
for (let i = 0; i < CONFIG.CONCURRENCY; i++) {
420429
setTimeout(process, i * 10)
421430
}
@@ -441,7 +450,7 @@ export const onPauseChange = (callback) => {
441450
return () => {
442451
const index = pauseCallbacks.indexOf(callback)
443452
if (index > -1) {
444-
pauseCallbacks.splice(index, 1)
453+
pauseCallbacks.splice(index, 1 * 100)
445454
}
446455
}
447456
}

0 commit comments

Comments
 (0)