Skip to content

Secure DFU: don't wait for a disconnect after the connection was already closed - #528

Open
niklavsBariss wants to merge 1 commit into
nordicsemi:mainfrom
mitigate-dev:fix/secure-dfu-no-wait-after-terminate
Open

niklavsBariss wants to merge 1 commit into
nordicsemi:mainfrom
mitigate-dev:fix/secure-dfu-no-wait-after-terminate

Conversation

@niklavsBariss

@niklavsBariss niklavsBariss commented Nov 19, 2026 •

Copy link
Copy Markdown

Problem

terminateConnection closes the GATT and reports the error, but its callers in SecureDfuImpl then return normally. From sendFirmware, performDfu carries on into waitUntilDisconnected, which waits for a disconnect a closed GATT never delivers. The IntentService thread parks there, so every later DfuServiceInitiator.start() queues behind it until the app is killed:

IntentService[DfuBaseService]:
  [4] no.nordicsemi.android.dfu.DfuBaseService.waitUntilDisconnected (DfuBaseService.java:1,626)
  [5] no.nordicsemi.android.dfu.SecureDfuImpl.performDfu (SecureDfuImpl.java:268)
  [6] no.nordicsemi.android.dfu.DfuBaseService.onHandleIntent (DfuBaseService.java:1,403)

From sendInitPacket they don't hang, but sendFirmware's first write then throws DeviceDisconnectedException, so the error is followed by a restart or a second broadcast with code 0.

How it shows up

Phone B resumes an upload phone A left in the bootloader, the upload ends in a CRC error, and the next start never connects. That CRC error is a separate bug (a stale stream mark after the resume), fixed in #530, stacked on this PR.

Fix

This PR makes a final CRC, file or progress error end the upload with one error report instead of leaving the DFU service stuck. Throwing lets onHandleIntent's existing DfuException handler terminate and report once, with the same error code. That handler logs through GattError.parse, hence the ERROR_PROGRESS_LOST case. LegacyDfuImpl's calls already return out of performDfu.

Verified

Xiaomi 14T (Android 16), 2.4.2 from source, with a fault that fails one object's CRC 3 times. Without the change, no DFU service destroyed and the next start never connects; with it, the service stops and the next start uploads.

@CLAassistant

CLAassistant commented Nov 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

2 participants