Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93768fb3 authored by Daniel Jacob Chittoor's avatar Daniel Jacob Chittoor Committed by Jackeagle
Browse files

Fix off-by-one error in flash retry counter

The retry logic used a 0-indexed retryCount but compared against
MAX_RETRIES with < operator, causing 4 attempts instead of 3:

  [DEBUG] Timeout on flashblob > boot_a (attempt 1/3)
  [DEBUG] Timeout on flashblob > boot_a (attempt 2/3)
  [DEBUG] Timeout on flashblob > boot_a (attempt 3/3)
  [DEBUG] Timeout on flashblob > boot_a (attempt 4/3)  <-- should not happen

The issue:
  - retryCount=0: "1/3", 0 < 3 true → retry
  - retryCount=1: "2/3", 1 < 3 true → retry
  - retryCount=2: "3/3", 2 < 3 true → retry
  - retryCount=3: "4/3", 3 < 3 false → throw

Rename retryCount to attempt (1-indexed) so the counter matches
the displayed value and MAX_ATTEMPTS reflects actual attempt count.
parent 04856102
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -72,8 +72,8 @@ export class Bootloader extends Device {
    );
  }

  async flashBlob(partition, blob, onProgress, retryCount = 0) {
    const MAX_RETRIES = 3;
  async flashBlob(partition, blob, onProgress, attempt = 1) {
    const MAX_ATTEMPTS = 3;
    const RETRY_DELAY_MS = 3000; // Wait before retry to let device stabilize

    // Pre-flash check: ensure device is still connected
@@ -90,8 +90,8 @@ export class Bootloader extends Device {
      return true;
    } catch (e) {
      if (e instanceof TimeoutError) {
        WDebug.log(`Timeout on flashblob > ${partition} (attempt ${retryCount + 1}/${MAX_RETRIES})`);
        if (retryCount < MAX_RETRIES) {
        WDebug.log(`Timeout on flashblob > ${partition} (attempt ${attempt}/${MAX_ATTEMPTS})`);
        if (attempt < MAX_ATTEMPTS) {
          // Wait before retry to allow device to recover
          WDebug.log(`Waiting ${RETRY_DELAY_MS}ms before retry...`);
          await new Promise(resolve => setTimeout(resolve, RETRY_DELAY_MS));
@@ -101,10 +101,10 @@ export class Bootloader extends Device {
            throw new Error(`Device disconnected during flash of ${partition}. Please reconnect and try again.`);
          }

          return await this.flashBlob(partition, blob, onProgress, retryCount + 1);
          return await this.flashBlob(partition, blob, onProgress, attempt + 1);
        }
        throw new Error(
          `Bootloader timeout: flashing ${partition} failed after ${MAX_RETRIES} retries. ` +
          `Bootloader timeout: flashing ${partition} failed after ${MAX_ATTEMPTS} attempts. ` +
          `Try using a different USB port or cable.`
        );
      } else {