Skip to content

Commit e087714

Browse files
committed
variable backoff
1 parent fccb2e0 commit e087714

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/js/tabs/onboard_logging.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,16 +491,14 @@ onboard_logging.initialize = function (callback) {
491491
show_saving_dialog();
492492

493493
const MAX_SIMPLE_RETRIES = 5;
494-
const RETRY_BACKOFF_MS = 30; // ms
494+
const BASE_RETRY_BACKOFF_MS = 30; // base backoff in ms
495495
const startTime = new Date().getTime();
496496

497497
prepare_file((fileWriter) => {
498498
FileSystem.openFile(fileWriter).then((file) => {
499499
openedFile = file;
500-
501500
let nextAddress = 0;
502501

503-
// Queue-based read function
504502
function readNextBlock() {
505503
if (saveCancelled || nextAddress >= maxBytes) {
506504
mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed);
@@ -516,6 +514,7 @@ onboard_logging.initialize = function (callback) {
516514
self.blockSize,
517515
(chunkAddress, chunkDataView, bytesCompressed) => {
518516
if (chunkDataView && chunkDataView.byteLength > 0) {
517+
// Good block
519518
simpleRetryCount = 0;
520519

521520
const blob = new Blob([chunkDataView]);
@@ -530,7 +529,6 @@ onboard_logging.initialize = function (callback) {
530529

531530
$(".dataflash-saving progress").attr("value", (nextAddress / maxBytes) * 100);
532531

533-
// Continue with next block
534532
readNextBlock();
535533
} else if (chunkDataView && chunkDataView.byteLength === 0) {
536534
// Zero-length block → EOF
@@ -540,17 +538,20 @@ onboard_logging.initialize = function (callback) {
540538
// Null/missing block
541539
if (simpleRetryCount < MAX_SIMPLE_RETRIES) {
542540
simpleRetryCount++;
541+
const backoff = BASE_RETRY_BACKOFF_MS * simpleRetryCount;
542+
543543
if (simpleRetryCount % 2 === 1) {
544544
console.warn(
545-
`Null/missing block at ${nextAddress}, retry ${simpleRetryCount}`,
545+
`Null/missing block at ${nextAddress}, retry ${simpleRetryCount}, backoff ${backoff}ms`,
546546
);
547547
}
548-
setTimeout(attemptRead, RETRY_BACKOFF_MS);
548+
549+
setTimeout(attemptRead, backoff);
549550
} else {
550551
console.error(
551552
`Skipping null block at ${nextAddress} after ${MAX_SIMPLE_RETRIES} retries`,
552553
);
553-
nextAddress += self.blockSize;
554+
nextAddress += self.blockSize; // skip block
554555
readNextBlock();
555556
}
556557
}

0 commit comments

Comments
 (0)