serial icon indicating copy to clipboard operation
serial copied to clipboard

unix.cpp uses tcdrain which has the potential to hang forever

Open mattconway1984 opened this issue 6 years ago • 0 comments

When trying to write data to a serial port (to check the presence of something connected to the serial port), I see the software hang.... I looked into it and discovered that the call

tcdrain(fd_)

tcdrain blocks until the output buffer has been emptied, however if there is no remote device to drain the the buffer it never drains so hangs forever.... I assume also if a remote device disconnects at some point during a data transmission the same issue will occur (I have not tested this theory).

One possible solution would be to create a thread which is used when writing data to the serial port, then create a thread watchdog that will kill the thread if a "wait for write data" timeout is exceeded, from what I can see, that is the most sensible way to unblock tcdrain.... Just make sure the write function blocks whilst the write thread is actively writing/flushing data to the port (until it's finished) or you'll end up with data corruption.... I'll try making a local fix for this and if successful I'll post details.

mattconway1984 avatar Aug 23 '18 11:08 mattconway1984