Skip to content

Conversation

@1e0ng
Copy link
Contributor

@1e0ng 1e0ng commented May 30, 2025

Previously, there was a concern that this part of the code could get stuck if the USB hub disconnected or didn't send a response.

Here's how I've addressed it:

  • I've added a 5-second timeout to wait for a response from the hub.
  • I'm also monitoring for a hub disconnection while waiting for the response.

If the hub disconnects, a RuntimeError will occur. If the operation times out, an asyncio.TimeoutError will occur.

I've also included some checks in tests/connections/test_pybricks.py to ensure this new behavior works as expected in both disconnection and timeout situations.

@1e0ng 1e0ng force-pushed the fix-usb-disconnect-timeout branch 2 times, most recently from b338722 to 11637be Compare May 30, 2025 14:54
…hod. Previously, there was a concern that this part of the code could get stuck if the USB hub disconnected or didn't send a response.

Here's how I've addressed it:
- I've added a 5-second timeout for waiting for a response from the hub.
- I'm now also monitoring for a hub disconnection while waiting for the response.

If the hub disconnects, a `RuntimeError` will occur.
If the operation times out, an `asyncio.TimeoutError` will occur.

I've also included some checks in `tests/connections/test_pybricks.py` to ensure this new behavior works as expected in both disconnection and timeout situations.
@1e0ng 1e0ng force-pushed the fix-usb-disconnect-timeout branch from 11637be to d2699e2 Compare May 30, 2025 14:56
timeout=1.0,
)
except asyncio.TimeoutError:
if self.connection_state_observable.value != ConnectionState.CONNECTED:
Copy link
Member

Choose a reason for hiding this comment

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

If race_disconnect() doesn't work, I don't think this will either since there is nothing to asynchronously set the connection state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. Since race_disconnect isn't working (I didn't know when I created this PR), probably not worth doing this change anymore. Let me know if you think otherwise. Thanks.

@1e0ng 1e0ng closed this Jun 4, 2025
@1e0ng 1e0ng deleted the fix-usb-disconnect-timeout branch June 4, 2025 12:46
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