You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
require "libusb"
usb = LIBUSB::Context.new
device = usb.devices(idVendor: 0x0100, idProduct: 0x0001).first
device.open do |dev|
if dev.kernel_driver_active?(0)
dev.detach_kernel_driver(0)
end
dev.claim_interface(0) {}
end
puts 'exiting'
to access my Generic HID device (a custom AVR ATMEGA32U4), in 20% of the cases I'm getting a segfault:
The error doesn't happen when using libusb in a similar way via C or Python.
Note that the error appears while exiting, after the last code statement.
The error disappears when running sleep 0.01 before exiting. (But not sleep 0.001, which seems to be a too short sleep duration).
Besides this error, other features of this library, like transfers, are properly functioning.
Thank you @erikarvstedt for your detailed bug report!
I tried to reproduce this issue with your provided script, changed to a vendor/product id of my system. Unfortunately I don't get any segfaults, even when running an endless bash loop. Your C backtrace isn't particular meaningful. I might help if you could install debug symbols of ruby (usually by the package manager) or/and if you could run the program via valgrind ruby segfault-demo.rb .
Moreover I remember that I've got a similar segfault in the early days of libusb development, which was caused by the non-deterministic order by which the ruby GC frees objects, when they are no longer in use. It happened, that some object made a call to the USB context while closing, although the context was already freed. I played a little bit with your program, but wasn't able to trigger a segfault either.
When running this simple script
to access my Generic HID device (a custom AVR ATMEGA32U4), in 20% of the cases I'm getting a segfault:
(Full diagnostic output)
The error doesn't happen when using
libusb
in a similar way viaC
orPython
.Note that the error appears while exiting, after the last code statement.
The error disappears when running
sleep 0.01
before exiting. (But notsleep 0.001
, which seems to be a too short sleep duration).Besides this error, other features of this library, like transfers, are properly functioning.
Environment:
Let me know if's there's anything more I can do to help debugging this.
The text was updated successfully, but these errors were encountered: