Problems with mio-serial - does not notice port going away

Hello fellow Rustaceans!

I have an unusual problem (I only have unusual problems...). I work with a device connected via USB serial port to a FreeBSD box (visible as /dev/ttyU0).

I'm trying to handle it via otherwise excellent tokio-serial crate. It relies on mio-serial, which in turn relies on serialport.

My problem is that said device occasionally disconnects itself (say, powercycle), but tokio-serial seems not to notice that and waits for data forever. I examined the examples from ground up and the culprit seems to be in mio-serial.

  • In serialport, in the example receive_data.rs everything works as expected - on disconenct I'm greeted by a wall of PipeBroken errors on read. This is good™.
  • In mio-serial, in the example of read_serialport.rs, the event of disconnection seems to be swallowed before reaching poll.poll(...), which in turn continues to wait indefinitely for data that no longer can come. For whatever reason, timeouts also seem not to be fired despite being set as low as 100ms...

I even tried circumnavigating the problem via a set of devd.conf rules called on creation/destruction of ttyU? devices that poke my process with SIGUSR1. The problem is that as long as the device is held open by my program, its entry does not disappear from /dev and devd rules are not fired.

Any hints on where to look?

Best regards,
Pawel

1 Like

Well, the problem is partially solved (circumnavigated actually)...

When I attempt to write to a vaporized port, everything instantly notices the device is gone and properly reports a failure. I just push a few bytes each second. Not the most elegant solution, but the best and the only working so far...