aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/query2
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-10-19 17:26:59 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-10-20 14:04:05 +0200
commitdb6e13b2e2bf1f5eb52909381bce65a099278e12 (patch)
tree6b5ed5034a64ddd6ce14e77e1c2d82e667e1a68a /src/main/java/com/google/devtools/build/lib/query2
parent95c63def1ea5b90447d79ebb7865328e938fd8bf (diff)
Replace Futures.dereference with the appropriate async method.
Futures.dereference is being deprecated and deleted, because it has a race condition where cancellation is not propagated. PiperOrigin-RevId: 172748120
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
index 137465245b..e1e03444e8 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
@@ -31,6 +31,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.AsyncCallable;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@@ -580,6 +581,14 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
}
}
+ private <R> ListenableFuture<R> safeSubmitAsync(AsyncCallable<R> callable) {
+ try {
+ return Futures.submitAsync(callable, executor);
+ } catch (RejectedExecutionException e) {
+ return Futures.immediateCancelledFuture();
+ }
+ }
+
@ThreadSafe
@Override
public QueryTaskFuture<Void> eval(
@@ -588,10 +597,9 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment<Target>
final Callback<Target> callback) {
// TODO(bazel-team): As in here, use concurrency for the async #eval of other QueryEnvironment
// implementations.
- Callable<QueryTaskFutureImpl<Void>> task =
+ AsyncCallable<Void> task =
() -> (QueryTaskFutureImpl<Void>) expr.eval(SkyQueryEnvironment.this, context, callback);
- ListenableFuture<QueryTaskFutureImpl<Void>> futureFuture = safeSubmit(task);
- return QueryTaskFutureImpl.ofDelegate(Futures.dereference(futureFuture));
+ return QueryTaskFutureImpl.ofDelegate(safeSubmitAsync(task));
}
@Override