diff --git a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/Ruffy.java b/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/Ruffy.java index 7350fadca6..e4801ff5c1 100644 --- a/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/Ruffy.java +++ b/ruffyscripter/src/main/java/org/monkey/d/ruffy/ruffy/driver/Ruffy.java @@ -277,11 +277,19 @@ public class Ruffy extends Service { } while(rtModeRunning) { - if(System.currentTimeMillis() > lastRtMessageSent +1000L) { - log("sending keep alive"); - synchronized (rtSequenceSemaphore) { - rtSequence = Application.sendRTKeepAlive(rtSequence, btConn); - lastRtMessageSent = System.currentTimeMillis(); + try { + if (System.currentTimeMillis() > lastRtMessageSent + 1000L) { + log("sending keep alive"); + synchronized (rtSequenceSemaphore) { + rtSequence = Application.sendRTKeepAlive(rtSequence, btConn); + lastRtMessageSent = System.currentTimeMillis(); + } + } + } catch (Exception e) { + if (rtModeRunning) { + fail("Error sending keep alive while rtModeRunning is still true"); + } else { + fail("Error sending keep alive. rtModeRunning is false, so this is most likely a race condition during disconnect"); } } try{