scanse / sweep-sdk

Sweep SDK
MIT License
90 stars 85 forks source link

libsweep does not handle unexpected unplug gracefully #102

Closed sevenbitbyte closed 7 years ago

sevenbitbyte commented 7 years ago

Root cause of: https://github.com/scanse/sweep-ros/issues/11

libsweep version + affected bindings

This is an issue in the libsweep software package

operating system

I've only tested on Linux, current Windows behavior in the same situation is unknown

Description:

I have determined the root cause of the issue to be here: https://github.com/scanse/sweep-sdk/blob/master/libsweep/src/unix/serial.cc#L332

When the device is unplugged this results in an EOF event where all calls to wait_readable will return true but calls to read returns zero bytes. This sends us into an infinite loop as this specific failure mode is not addressed at all in the loop so we're stuck here forever.

Repro steps

Observed result

Expected result

sevenbitbyte commented 7 years ago

Examining other failure modes in libsweep it appears the right thing here is to throw an exception(possibly causing the calling process to terminate abruptly). I will produce a patched version to bring this failure mode inline with the behavior I see employed elsewhere.