Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transport): transferOut timeout must be inside try block #16861

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

mroz22
Copy link
Contributor

@mroz22 mroz22 commented Feb 5, 2025

argh face-palm me 🤕 🌴.
image

in #16793 I made some last time changes - moving the timeout outside of try block so that I can clear it in finally easily which resulted in the error from device.reset not being catched

Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

The changes modify the write method within the UsbApi class in packages/transport/src/api/usb.ts. The primary adjustment is in the handling of the reset method call on the device object during a timeout scenario. The previous implementation called the reset method directly, which could result in unhandled promise rejections if the reset operation failed. The new implementation uses device?.reset().catch(() => {}), ensuring that any errors from the reset operation are caught and ignored, thus preventing unhandled promise rejections. This change improves error handling during timeouts without affecting the overall logic or control flow of the method.

Possibly related PRs

  • fix(transport): usb - write timeout #16793: The changes in this PR enhance error handling in the write method of the UsbApi class, while the retrieved PR introduces a timeout mechanism in the same write method, indicating a direct relationship between the two.

Suggested labels

release

Suggested reviewers

  • szymonlesisz
  • martykan
  • marekrjpolak

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7e26b and 616b173.

📒 Files selected for processing (1)
  • packages/transport/src/api/usb.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/transport/src/api/usb.ts
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: PR-check / web-override init-api-flaky
  • GitHub Check: PR-check / node-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: PR-check / node-override init-api-flaky
  • GitHub Check: PR-check / web-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: build-deploy
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: build-web
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: transport-e2e-test
  • GitHub Check: Analyze with CodeQL (javascript)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mroz22 mroz22 added the release Will be included in the upcoming release. Needs to be backported to the release branch. label Feb 5, 2025
@mroz22 mroz22 marked this pull request as ready for review February 5, 2025 20:18
@mroz22 mroz22 requested a review from szymonlesisz as a code owner February 5, 2025 20:18
@mroz22 mroz22 added the no-project This label is used to specify that PR doesn't need to be added to a project label Feb 5, 2025
Copy link
Contributor

@marekrjpolak marekrjpolak left a comment

Choose a reason for hiding this comment

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

I believe this change is irrelevant as errors thrown from device.reset() from inside 1000 ms timeout cannot be caught by synchronous try block.

@marekrjpolak
Copy link
Contributor

Generally I think this could be job for scheduleAction as it's a logic which can be either aborted from outside or timeouted from inside.

As a quicker fix, could it be possible to abort the signal in the timeout, instead of directly calling device.reset()? It should do the same thing inside abortableMethod, right?

@mroz22 mroz22 removed the release Will be included in the upcoming release. Needs to be backported to the release branch. label Feb 7, 2025
@mroz22 mroz22 force-pushed the fix-recent-bug-in-usb branch from 022e194 to 5b7e26b Compare February 10, 2025 06:32
@mroz22
Copy link
Contributor Author

mroz22 commented Feb 10, 2025

As a quicker fix, could it be possible to abort the signal in the timeout, instead of directly calling device.reset()? It should do the same thing inside abortableMethod, right?

I am afraid that it can't be done easily. This signal that is used inside usb.write is passed from the caller and it is the same signal that is used also for read which must not be timed-out.

but what about simply attaching catch handler to device.reset? it should do the trick, shoudln't it? 5b7e26b.

@marekrjpolak
Copy link
Contributor

but what about simply attaching catch handler to device.reset? it should do the trick, shoudln't it?

Yeah I thought that error from device.reset() itself must be caught. If we presume that calling reset will cause an error to be thrown from inside the device.transferOut(), it should be perfectly fine.

@mroz22
Copy link
Contributor Author

mroz22 commented Feb 10, 2025

If we presume that calling reset will cause an error to be thrown from inside the device.transferOut()

yes, that is exactly what happens

@mroz22
Copy link
Contributor Author

mroz22 commented Feb 10, 2025

/rebase

Copy link

@trezor-ci trezor-ci force-pushed the fix-recent-bug-in-usb branch from 5b7e26b to 616b173 Compare February 10, 2025 10:39
@mroz22 mroz22 enabled auto-merge (rebase) February 10, 2025 15:44
@mroz22 mroz22 merged commit 723a253 into develop Feb 10, 2025
43 of 44 checks passed
@mroz22 mroz22 deleted the fix-recent-bug-in-usb branch February 10, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-project This label is used to specify that PR doesn't need to be added to a project
Projects
Status: 🤝 Needs QA
Development

Successfully merging this pull request may close these issues.

2 participants