embassy-usb-host: stop descriptor retries on disconnect - #7030
Merged
Merged
Conversation
|
👋 Welcome, @ShangYJQ, and thanks for opening your first pull request here! If you haven't already, please give the contributor guide a read. |
leftger
approved these changes
Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stop
retry_descriptor()from retrying descriptor reads afterPipeError::Disconnected.A disconnect is terminal: retrying the request starts a new transfer after
the device has already left the bus. Depending on the host driver, that
transfer may never complete.
Problem
I reproduced this with a USB device that disconnects and re-enumerates
during enumeration.
The host driver (
embassy-usb-synopsys-otg, ESP32-S3) correctly propagatedthe disconnect to the in-flight transfer:
However,
retry_descriptor()treatedDisconnectedlike any otherdescriptor-read error. After the 5 ms retry delay it issued the same
GET_DESCRIPTORrequest again.At that point the device was already disconnected, so the new transfer
remained pending indefinitely and enumeration never returned.
Fix
Return
Disconnectedimmediately fromretry_descriptor()while preservingthe existing retry behavior for other errors such as
Stall.The helper is used with both
PipeErrorandHostError, so the error isconverted to
HostErroronly for the terminal-disconnect check.Testing
Added regression coverage verifying that:
Disconnectedis returned immediately and the operation is attemptedexactly once (both as
PipeErrorand asHostError::PipeError).Stallremains retryable and can succeed on a subsequent attempt.Without the fix, the disconnect test fails because the read is attempted
4 times (the initial attempt plus 3 retries).
I also verified the fix on hardware using an ESP32-S3 USB host and a device
that re-enumerates from
04b4:2412to045e:028e.Before the fix, enumeration remained pending after the intermediate device
disconnected.
After the fix: