From 0021e063f209c4e7d620a382fd553b23bf782564 Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Thu, 2 Jun 2016 14:33:24 -0700 Subject: [PATCH] benchmarks: reset context in AsyncClient to avoid chaining. Fixes #1878 --- .../java/io/grpc/benchmarks/qps/AsyncClient.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncClient.java b/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncClient.java index d02a06bd5e..6cefafbec6 100644 --- a/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncClient.java +++ b/benchmarks/src/main/java/io/grpc/benchmarks/qps/AsyncClient.java @@ -54,6 +54,7 @@ import com.google.common.base.Preconditions; import com.google.protobuf.ByteString; import io.grpc.Channel; +import io.grpc.Context; import io.grpc.ManagedChannel; import io.grpc.Status; import io.grpc.benchmarks.proto.BenchmarkServiceGrpc; @@ -198,10 +199,15 @@ public class AsyncClient { histogram.recordValue((now - lastCall) / 1000); lastCall = now; - if (endTime > now) { - stub.unaryCall(request, this); - } else { - future.done(); + Context prevCtx = Context.ROOT.attach(); + try { + if (endTime > now) { + stub.unaryCall(request, this); + } else { + future.done(); + } + } finally { + Context.current().detach(prevCtx); } } });