We're using jrxtx to communicate with a tty device on an embeded linux device. I've recently discovered a deadlock condition on attempting to write to the port:
...
os.write(bb.array(), 0, bb.position());
os.flush();
The flush then blocks indefinitely:
java.lang.Thread.State: RUNNABLE
at gnu.io.RXTXPort.nativeDrain(Native Method)
at gnu.io.RXTXPort$SerialOutputStream.flush(RXTXPort.java:1188)
at org.openmuc.jrxtx.JRxTxPort$SerialOutputStream.flush(JRxTxPort.java:231)
....
Since this happens 1/1000 of the time, it is likely some hardware glitch causes the initial lock-up, however restarting the JVM clears the issue so it must be temporary.
The issue is that there are calls which potentially block indefinitely.
Is there any know way to wrap this invocation so that it can time out without blocking?