From 9655088708bc5f5c3277d9ddc3c224b3a27320f8 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Tue, 29 Mar 2016 10:45:43 -0400 Subject: [PATCH] Provide a timeout for query that might run in UI thread. GdbReverseToggleCommand extends AbstractDebugCommand so as to be able to block without risking a deadlock. However, this only applies to doExecute() and isExecutable(). GdbReverseToggleCommand has two other methods that use queries, and those are at risk of a deadlock: isReverseToggled() and getReverseDebugMethod(). Those queries must have a timeout to avoid any risk of deadlock. Change-Id: Ia410b8f102638965ccbf8ac9deda06dc4efc5f0d --- .../internal/ui/commands/GdbReverseToggleCommand.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java index d66b1b78cb0..8b910639b8f 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbReverseToggleCommand.java @@ -279,12 +279,15 @@ public class GdbReverseToggleCommand extends AbstractDebugCommand implements ICh }; try { fExecutor.execute(isToggledQuery); - return isToggledQuery.get(); + return isToggledQuery.get(500, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } catch (ExecutionException e) { } catch (RejectedExecutionException e) { // Can be thrown if the session is shutdown - } + } catch (TimeoutException e) { + // If we timeout, we default to false. + // This is to avoid a deadlock + } return false; } @@ -390,6 +393,8 @@ public class GdbReverseToggleCommand extends AbstractDebugCommand implements ICh } catch (ExecutionException e) { } catch (RejectedExecutionException e) { } catch (TimeoutException e) { + // If we timeout, we default to OFF. + // This is to avoid a deadlock } return ReverseDebugMethod.OFF;