Skip to content

fix(dfu): harden flash_beacon.sh with timeouts + retries#15

Merged
ak2k merged 1 commit into
mainfrom
chore/harden-flash-beacon-timeouts
Apr 26, 2026
Merged

fix(dfu): harden flash_beacon.sh with timeouts + retries#15
ak2k merged 1 commit into
mainfrom
chore/harden-flash-beacon-timeouts

Conversation

@ak2k

@ak2k ak2k commented Apr 26, 2026

Copy link
Copy Markdown
Owner

mcumgr was previously called with no timeout flags and no wall-clock
cap. A stuck SMP transfer (BLE link drop, MTU stall, peer reboot
mid-upload) would hang the script indefinitely with no useful output.

Hardening:

  • set -euo pipefail (script previously continued past a failed upload
    to image confirm, which would confirm against potentially stale state)
  • mcumgr -t 5 -r 5 on every call: 5s per-RPC timeout, 5 retries per
    packet — covers transient MTU/link issues without masking a real hang
  • timeout 300s wall-clock cap on the upload step (SIGTERM, then SIGKILL
    after 10s grace) — 200 KB image at MTU 498 is 30-90s in practice
  • MCUMGR env var with sane fallback (was hardcoded to ~/go/bin/mcumgr)
  • UPLOAD_TIMEOUT env var for tuning
  • bash array variables for connection args (eliminates shell-quoting
    fragility around the connstring)
  • Argument validation refactored to use ${VAR:-} so unset args fail
    cleanly under set -u
  • sudo -v to prime the credential cache (was: sudo echo "")
  • shellcheck clean

Behavior on success is unchanged. Failure modes that previously hung
silently now exit non-zero with a clear cause.

mcumgr was previously called with no timeout flags and no wall-clock
cap. A stuck SMP transfer (BLE link drop, MTU stall, peer reboot
mid-upload) would hang the script indefinitely with no useful output.

Hardening:

- set -euo pipefail (script previously continued past a failed upload
  to image confirm, which would confirm against potentially stale state)
- mcumgr -t 5 -r 5 on every call: 5s per-RPC timeout, 5 retries per
  packet — covers transient MTU/link issues without masking a real hang
- timeout 300s wall-clock cap on the upload step (SIGTERM, then SIGKILL
  after 10s grace) — 200 KB image at MTU 498 is 30-90s in practice
- MCUMGR env var with sane fallback (was hardcoded to ~/go/bin/mcumgr)
- UPLOAD_TIMEOUT env var for tuning
- bash array variables for connection args (eliminates shell-quoting
  fragility around the connstring)
- Argument validation refactored to use ${VAR:-} so unset args fail
  cleanly under set -u
- sudo -v to prime the credential cache (was: sudo echo "")
- shellcheck clean

Behavior on success is unchanged. Failure modes that previously hung
silently now exit non-zero with a clear cause.
@ak2k ak2k merged commit 6e8da6e into main Apr 26, 2026
18 checks passed
@ak2k ak2k deleted the chore/harden-flash-beacon-timeouts branch April 26, 2026 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant