POSIX open() blocks indefinitely for serial port file descriptor

I have a USB CDC ACM device which appears in the /dev filesystem as /dev/tty.usbmodem... and /dev/cu.usbmodem... . Most of the time, I am able to read from and write to this device using serial port libraries, including the POSIX calls open(), read(), write(), etc.


However, if the device is plugged in, then my mac goes to sleep for at least a few minutes (3 seems very repeatable), when the PC wakes up and I try to open the file, the call to open() blocks or hangs forever. This also happens if I use the `O_NONBLOCK` option, which should return immediately. I am not loading any special device drivers, but instead relying on the built-in driver loaded for USB CDC ACM devices.


This affects not only my software, but also built-in utilities including `screen` and other common libraries including pyserial. I've tried both the /dev/tty.usbmodem... and /dev/cu.usbmodem.. filepaths. This occurs across multiple versions of macOS including Mojave and High Sierra. I've tried using direct USB-C cable connections to the device and different USB-C hubs, all with the same effect.


From the output of

ioreg -r -c IOUSBHostDevice -l
I've confirmed that the com.apple.driver.usb.cdc.acm driver is being loaded for my device. When I unload that driver, the device no longer appears, and when it is reloaded, everything works as normal.


After a sleep, I tried to unload and reload the driver without unplugging and reconnecting the physical, hub, but this also does not resolve the issue.

sudo kextunload -b com.apple.driver.usb.cdc.acm 
sudo kextload -b com.apple.driver.usb.cdc.acm

Replies

I’m not sure what’s going on here, but you should definitely file a bug about it. The real kicker is this:

This affects not only my software, but also built-in utilities including

screen
and other common libraries including pyserial.

Even if there is a workaround for your code, you can’t apply that workaround to

screen
, so it makes sense to file a bug.

My recommendation is that you reproduce the problem with

screen
and then trigger a sysdiagnose log, and attach that log to your bug report. See our Bug Reporting > Profiles and Logs page for more info on sysdiagnose logs.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for the suggestion. I filed a bug report using feedback assistant, number FB6153687, with a sysdiagnose log.