Repository navigation
Enforce 2s minimum gap between port disable and re-enable in enable_only - #15032
Conversation
Nir-Az
left a comment
There was a problem hiding this comment.
Code Review — PR #15032 · Enforce 2s minimum gap in enable_only
The fix is correct and well-motivated — the empirical data table in the PR description is excellent. A few items to address before merging:
Summary of inline comments
| Line | Severity | Topic |
|---|---|---|
| 620 | disable_t set after hub.disable_ports() — should be before to cover async port-off |
|
| 620 | Use timestamp() (perf_counter) instead of time.time() — already imported, monotonic |
|
| 625 | Magic number 2.0 → named constant _MIN_PORT_RECYCLE_GAP_S |
|
| 627 | 💡 Enhancement | Add log.d(...) before the sleep for CI visibility |
Missing automated test
The test plan is entirely manual / libci-run. Consider adding a unit test (e.g., in unit-tests/py/) that:
- Mocks
hub.disable_ports,_wait_until_removed, andtime.sleep - Verifies that when
_wait_until_removedreturns in < 2 s,time.sleepis called with a value ≈2.0 − elapsed - Verifies that when
_wait_until_removedalready took ≥ 2 s,time.sleepis not called
This would prevent the gap from being accidentally removed in a future refactor.
🤖 Auto-generated comment by rs-agentic bot
| hub.disable_ports( enabled_ports ) | ||
| disable_t = time.time() | ||
| _wait_until_removed( sns_to_remove, timeout = timeout ) | ||
| # Acroname USBHub3p firmware (2.12.2) wedges with -71 cascades when |
There was a problem hiding this comment.
Please rephrase. wedges, cascades, not clear
There was a problem hiding this comment.
Rewrote in f3370bf. The new docstring on the constant reads:
Minimum elapsed time (seconds) required between issuing a port disable and a subsequent port enable on the Acroname USBHub3p (firmware 2.12.2). Below this threshold, sustained disable/enable traffic on high-current ports (observed with D585S, ~1 A idle) can leave the BrainStem control endpoint unresponsive.
…ports with named constant and monotonic timer
|
Addressed review comments in
Also fixed a latent name-shadowing bug in both functions: the existing |
Summary
Defensive guard in
Acroname.disable_ports/Acroname.enable_portsthat enforces a minimum 2 s gap between issuing a port-disable and a subsequent port-enable on the same hub. Below this threshold the Acroname USBHub3p (firmware 2.12.2) BrainStem control endpoint can stop responding under sustained disable/enable traffic on high-current ports — most reliably reproduced with D585S, which idles around 1 A.This is not a fix for a deterministic failure. The wedge is intermittent in production. The patch removes the timing trigger by guaranteeing a known-safe minimum, so the failure mode cannot be hit even when other layers (test retry path, fast machine, post-streaming cleanup) compress the gap.
Implementation
_MIN_PORT_RECYCLE_GAP_S = 2.0inacroname.pyAcroname.__init__adds_last_disable_t = NoneAcroname.disable_portsrecordstime.monotonic()after a successful disableAcroname.enable_portschecks at start and sleeps just enough to honour the gap; logslog.d(f"waiting {settle:.2f}s for Acroname port-recycle gap")import timeshadows that would have causedUnboundLocalErrorwhen the module-leveltimeis referenced earlier in the functiondevices.pyis untouched — initial revision had the logic there but per review (@OhadMeir) it belongs in the hub-specific class.Threshold data (vtglnx163, D585S on Acroname port 4)
-71cascade across both stems. Recovery: physical DC power-cycle of the hub.device not accepting address ... -62); only 3/10 cycles complete USB enumerationlibci 11369 showed disable→enable gaps as low as 259 ms when consecutive tests target the same device.
Validation on real pytest workload
Ran
pytest unit-tests/live/ --device D585S --context nightlyagainst the same suite, with and without the patch:err = -71eventscannot disableeventsSame exact failure list both times — the 4 non-passes are test-internal (
pytest-enumerate-devices,pytest-rs-convert-to-db3FAILED;multi_devices/*ERROR) and not caused by hub timing. Cost of the patch on this 6-minute run: ~24 s (~7%).Today we couldn't reliably trigger the wedge through pytest's natural pacing (re-enumeration takes ~3.8 s, naturally giving the hub breathing room), but yesterday's stress tests prove the trigger is real once cycle gaps drop below 2 s.
Test plan
py_compile)--device D585S --context nightly) with and without patch — same results🤖 Generated with Claude Code