question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pyusb segfaults under macOS with devices stalling on a SET_INTERFACE request

See original GitHub issue

https://github.com/libusb/libusb/issues/1011#issuecomment-983208629

For reference, we can reproduce this issue with a STM32F4-Discovery board, or SparkFun Thing Plus board (https://www.sparkfun.com/products/17712), using a libopencm3 example modified with this patch, which makes it stall the pipe on a SET_INTERFACE request. fw_set_interface_stall.patch.txt

Just a run log for reference using pyusb under my Mac Mini M1. Not so sure why pyusb segfaults though.

Tormod is suggesting that we look into the error processing path in pyusb.

mcuee@mcuees-Mac-mini ~ % export LIBUSB_DEBUG=4
mcuee@mcuees-Mac-mini ~ % python3
Python 3.9.8 (main, Nov 10 2021, 03:48:35)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import usb
>>> dev = usb.core.find(idVendor=0x0483)
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000013] [00004d43] libusb: debug [libusb_init] libusb v1.0.24.11675
...

>>> dev.set_configuration()
[ 3.254908] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
[ 3.255204] [000075b5] libusb: debug [libusb_open] open 2.20
[ 3.255456] [000075b5] libusb: debug [darwin_open] device open for access
[ 3.255489] [000075b5] libusb: debug [libusb_set_configuration] configuration 1

>>> cfg = dev.get_active_configuration()
[15.680978] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
>>> print(cfg)
[21.631005] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
[21.631410] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
[21.631596] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
[21.631676] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
[21.631780] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
[21.631976] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
[21.632184] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
  CONFIGURATION 1: 100 mA ==================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x43 (67 bytes)
   bNumInterfaces       :    0x2
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0
   bmAttributes         :   0x80 Bus Powered
   bMaxPower            :   0x32 (100 mA)
    INTERFACE 0: Reserved ==================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0x0 Reserved
     bInterfaceSubClass :    0x2
     bInterfaceProtocol :    0x1
     iInterface         :    0x0
      ENDPOINT 0x83: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x83 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x10 (16 bytes)
       bInterval        :   0xff
    INTERFACE 1: CDC Data ==================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x1
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x2
     bInterfaceClass    :    0xa CDC Data
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x0
      ENDPOINT 0x1: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x1 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1
      ENDPOINT 0x82: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0x1

>>> dev.set_interface_altsetting(interface = 0, alternate_setting = 0)
[65.169062] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
[65.169440] [000075b5] libusb: debug [libusb_get_config_descriptor] index 0
[65.169628] [000075b5] libusb: debug [libusb_claim_interface] interface 0
[65.170967] [000075b5] libusb: debug [get_endpoints] building table of
endpoints.
[65.171743] [000075b5] libusb: debug [get_endpoints] interface: 0 pipe
1: dir: 1 number: 3
[65.171813] [000075b5] libusb: debug [darwin_claim_interface] interface opened
[65.171847] [000075b5] libusb: debug
[libusb_set_interface_alt_setting] interface 0 altsetting 0
[65.176102] [000075b5] libusb: warning
[darwin_set_interface_altsetting] SetAlternateInterface: pipe is
stalled
[65.176876] [000075b5] libusb: info [darwin_claim_interface]
USBInterfaceOpen: another process has device opened for exclusive
access
[65.177150] [000075b5] libusb: error [darwin_set_interface_altsetting]
could not reclaim interface
zsh: segmentation fault  python3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mcueecommented, Dec 1, 2021

We can always reopen if later we think there are changes required for pyusb.

1reaction
mcueecommented, Dec 1, 2021

Can you get a log with PYUSB_DEBUG=debug set?

Yes I will post a log this evening.

Also, what version of PyUSB is being used?

Git head version of pyusb.

Read more comments on GitHub >

github_iconTop Results From Across the Web

libusb_set_interface_alt_setting returns kIOUSBPipeStalled ...
If you look at the log in pull request #843, the call failed with a pipe stall error, so I think the device...
Read more >
Untitled
Avaya dmcc call recording, Colonel de beers wiki, Anton martynov vivaldi, Three for one ... Set interface in java, Hazara indian mongolia, Sandro...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found