Skip to content

Fix gs_usb USB resource cleanup on Windows - #2106

Open
dmg210 wants to merge 1 commit into
hardbyte:mainfrom
dmg210:main
Open

dmg210 wants to merge 1 commit into
hardbyte:mainfrom
dmg210:main

Conversation

@dmg210

@dmg210 dmg210 commented Oct 20, 2026 •

Copy link
Copy Markdown

Problem

On Windows, reopening a gs_usb CAN adapter for a subsequent operation can fail with:

usb.core.USBError: [Errno 13] Access denied (insufficient permissions)

In my application, the first CAN operation completed successfully, but opening the adapter for the second operation failed. The device remained discoverable.

Fix

Explicitly dispose of the underlying PyUSB device resources during GsUsbBus.shutdown().

Testing

Tested on Windows 10 with Python 3.11, python-can 4.6.1, gs_usb 0.3.1, and a CANBUS adapter using WinUSB.

After adding usb.util.dispose_resources(self.gs_usb.gs_usb) to the shutdown method, I was able to complete a second operation successfully.

Further testing of repeated open/close cycles has been completed locally.

Type of Change

  • Bug fix

On Windows, reopening a `gs_usb` CAN adapter for a subsequent operation can fail with:
`usb.core.USBError: [Errno 13] Access denied (insufficient permissions)`
Comment thread can/interfaces/gs_usb.py
pass
finally:
usb.util.dispose_resources(gs_usb.gs_usb)
usb.util.dispose_resources(self.gs_usb.gs_usb)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

instead of this repetition, i'd prefer a try-finally around the whole function body.

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