Skip to content

Commit c74854b

Browse files
authored
Merge pull request #531 from alex268/master
Move discovery and attachStream outside of the client context
2 parents 699d3fe + da6b944 commit c74854b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

core/src/main/java/tech/ydb/core/impl/YdbDiscovery.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.concurrent.locks.ReentrantLock;
1212
import java.util.stream.Collectors;
1313

14+
import io.grpc.Context;
1415
import org.slf4j.Logger;
1516
import org.slf4j.LoggerFactory;
1617

@@ -147,6 +148,9 @@ private void tick() {
147148
private void runDiscovery() {
148149
lastUpdateTime = handler.instant();
149150
try {
151+
// Execute discovery call outside current context to avoid span propogation
152+
Context ctx = Context.ROOT.fork();
153+
Context previous = ctx.attach();
150154
final GrpcTransport transport = handler.createDiscoveryTransport();
151155
try {
152156
logger.debug("execute list endpoints on {} with timeout {}", transport, discoveryTimeout);
@@ -168,6 +172,8 @@ private void runDiscovery() {
168172
} catch (Throwable th) {
169173
transport.close();
170174
throw th;
175+
} finally {
176+
ctx.detach(previous);
171177
}
172178
} catch (Throwable th) {
173179
handleDiscoveryResult(null, th);

query/src/main/java/tech/ydb/query/impl/QueryServiceRpc.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.concurrent.CompletableFuture;
44

5+
import io.grpc.Context;
6+
57
import tech.ydb.core.Result;
68
import tech.ydb.core.grpc.GrpcReadStream;
79
import tech.ydb.core.grpc.GrpcRequestSettings;
@@ -68,7 +70,14 @@ public CompletableFuture<Result<YdbQuery.DeleteSessionResponse>> deleteSession(
6870

6971
public GrpcReadStream<YdbQuery.SessionState> attachSession(
7072
YdbQuery.AttachSessionRequest request, GrpcRequestSettings settings) {
71-
return transport.readStreamCall(QueryServiceGrpc.getAttachSessionMethod(), settings, request);
73+
// Execute attachSession call outside current context to avoid span propogation
74+
Context ctx = Context.ROOT.fork();
75+
Context previous = ctx.attach();
76+
try {
77+
return transport.readStreamCall(QueryServiceGrpc.getAttachSessionMethod(), settings, request);
78+
} finally {
79+
ctx.detach(previous);
80+
}
7281
}
7382

7483
public CompletableFuture<Result<YdbQuery.BeginTransactionResponse>> beginTransaction(

0 commit comments

Comments
 (0)