Skip to content

Fix(hw-ledger): reset transport on operation errors and add explicit disconnect API#2024

Merged
TarikGul merged 2 commits intopolkadot-js:masterfrom
F-OBrien:closeTransport
Mar 22, 2026
Merged

Fix(hw-ledger): reset transport on operation errors and add explicit disconnect API#2024
TarikGul merged 2 commits intopolkadot-js:masterfrom
F-OBrien:closeTransport

Conversation

@F-OBrien
Copy link
Copy Markdown
Contributor

Summary

This PR updates hw-ledger transport lifecycle handling in two places:

  • close/reset the active transport when a withApp operation fails
  • add an explicit disconnect() method on Ledger and LedgerGeneric so consumers can clean up intentionally

Why

While testing extension flows, I kept hitting transport/session problems after failures and across hook lifecycles:

  • if an operation fails, keeping the same app/transport around can cause follow-up errors and inconsistent state
  • consumers need a reliable way to release an active transport during lifecycle transitions (unmount, refresh, replacing an instance)

Related context:

Behavior:

  • on withApp error: best-effort transport.close(), clear cached app, rethrow original error
  • disconnect(): explicit consumer API to close an active transport without waiting for an internal failure path

Why disconnect() is needed

In useLedger-style flows, one hook instance can unmount while its transport is still open.
The next instance may then fail with “already open” transport errors.
disconnect() gives consumers a clean, explicit teardown point to avoid that.

Compatibility / risk

  • error-path behavior is intentionally stricter: failed operations now reset transport state instead of leaving a possibly bad session alive

Copy link
Copy Markdown
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks solid! Thanks

@TarikGul TarikGul merged commit 4a5b6ac into polkadot-js:master Mar 22, 2026
4 checks passed
@polkadot-js-bot
Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Mar 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants