Skip to content

fix: stabilize device cleanup and pace Pro2/Neo USB signing - #919

Open
wabicai wants to merge 8 commits into
onekeyfrom
fix/portfolio-ble-retry
Open

fix: stabilize device cleanup and pace Pro2/Neo USB signing#919
wabicai wants to merge 8 commits into
onekeyfrom
fix/portfolio-ble-retry

Conversation

@wabicai

@wabicai wabicai commented Sep 5, 2026

Copy link
Copy Markdown
Member

Cancelling a BLE operation or immediately starting another call could overlap old connection setup or teardown. Repeated calls and SDK resets also left request records and React Native BLE resources behind.

Requests are registered before queue waits, and cancellation uses the existing request signal and per-device cleanup barrier. Device cancellation captures the old commands and run state and is deduplicated per connection attempt. Completed V1/V2 calls preserve their acknowledged result while registering the actual run cleanup with that same barrier, so the next acquire waits for release. A cleanup deadline does not make an unfinished connection reusable.

Pro2 and Neo signing calls over browser WebUSB, desktop WebUSB, and Node USB now append a one-second cooldown to that per-connectId post-call barrier. The current signing result is returned at the existing time; only the next device call waits. BLE, older device families, non-signing methods, and other devices remain unaffected. The same cooldown is registered after success, cancellation, or a signing error so an immediate retry cannot race device recovery.

React Native V1 cancellation rejects its pending read and waits for native disconnect. SDK disposal now reaches Core and drains the transport's scans, scan timers, pending reads and owned native connections. Ordinary disposal leaves the shared ble-plx manager available to other connectors. A manager reset waits for asynchronous singleton destruction before another transport can acquire; destruction failures or deadlines do not permit reuse of the old manager. Both SDK entries remove request records when calls settle, including out-of-order failures.

Connection setup failures stop the outer poll. Existing scan/connect/GATT timing logs remain available; scan windows, connection retry parameters and transfer packet sizes are unchanged.

Validation:

  • yarn agent:check --profile commit passed on the latest commit.
  • yarn workspace @onekeyfe/hd-core test device-lifecycle-events.test.ts --runInBand passed: 83 tests.
  • yarn workspace @onekeyfe/hd-core build passed.
  • Focused ESLint and Prettier checks passed for the changed files.
  • The latest yarn agent:check --profile pr reached full lint, then the local shared dependency environment failed while loading the TypeScript import resolver for the unrelated expo-playground file CollapsibleJsonViewer.tsx; GitHub CI is running the clean-environment checks.
  • SDK entry regressions passed separately with yarn jest --runInBand --runTestsByPath packages/hd-ble-sdk/__tests__/device-state-events.test.ts packages/hd-common-connect-sdk/__tests__/device-state-events.test.ts.
  • Regressions cover V1/V2 cleanup before the next acquire, queued/repeated/late cancellation, reset waiting across transport instances, failed native destruction, scan timer cleanup, pending-read/native-disconnect settlement, SDK request/listener cleanup, and Pro2/Neo USB signing cooldown boundaries.

Companion App fix: OneKeyHQ/app-monorepo#13196.
Related symptom: https://onekeyhq.atlassian.net/browse/OK-62115.

Physical iOS/Android/Electron cancellation, transfer performance, Pro2/Neo continuous USB signing, and post-upload stability still require device validation. This does not establish the cause of the reported iOS freeze. SDK publication and the App dependency update are separate follow-up work.

@wabicai wabicai changed the title fix: stop BLE retries after cancellation and setup failure fix: drain BLE cancellation before retrying device communication Sep 5, 2026
@wabicai wabicai changed the title fix: drain BLE cancellation before retrying device communication fix: drain BLE requests and clean up native SDK resources Sep 5, 2026
Comment thread packages/core/src/core/index.ts
Comment thread packages/hd-ble-sdk/__tests__/device-state-events.test.ts
@wabicai wabicai changed the title fix: drain BLE requests and clean up native SDK resources fix: stabilize device cleanup and pace Pro2/Neo USB signing Sep 7, 2026
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