Skip to content

Commit d898ace

Browse files
committed
fix: RPC mode does not honor timeout
During the refactoring of the connection the timeout for unary calls got lost. This adds the timeout back into the mix. TODO: - [ ] adapt gherkin tests for contextEnrichment to do handle stale seperately for file and inprocess Signed-off-by: Simon Schrottner <[email protected]>
1 parent 2bf613f commit d898ace

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

Diff for: .gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[submodule "providers/flagd/test-harness"]
55
path = providers/flagd/test-harness
66
url = https://github.com/open-feature/test-harness.git
7-
branch = v2.2.0
7+
branch = v2.5.0
88
[submodule "providers/flagd/spec"]
99
path = providers/flagd/spec
1010
url = https://github.com/open-feature/spec.git

Diff for: providers/flagd/spec

Diff for: providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/common/GrpcConnector.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class GrpcConnector<T extends AbstractStub<T>, K extends AbstractBlocking
3232
/**
3333
* The blocking service stub for making blocking GRPC calls.
3434
*/
35-
private final K blockingStub;
35+
private final Function<ManagedChannel, K> blockingStubFunction;
3636

3737
/**
3838
* The GRPC managed channel for managing the underlying GRPC connection.
@@ -59,6 +59,8 @@ public class GrpcConnector<T extends AbstractStub<T>, K extends AbstractBlocking
5959
*/
6060
private final Consumer<T> streamObserver;
6161

62+
private final FlagdOptions options;
63+
6264
/**
6365
* Indicates whether the connector is currently connected to the GRPC service.
6466
*/
@@ -85,11 +87,12 @@ public GrpcConnector(
8587

8688
this.channel = channel;
8789
this.serviceStub = stub.apply(channel).withWaitForReady();
88-
this.blockingStub = blockingStub.apply(channel).withWaitForReady();
90+
this.blockingStubFunction = blockingStub;
8991
this.deadline = options.getDeadline();
9092
this.streamDeadlineMs = options.getStreamDeadlineMs();
9193
this.onConnectionEvent = onConnectionEvent;
9294
this.streamObserver = eventStreamObserver;
95+
this.options = options;
9396
}
9497

9598
/**
@@ -126,7 +129,7 @@ public void initialize() throws Exception {
126129
* @return the blocking service stub
127130
*/
128131
public K getResolver() {
129-
return blockingStub;
132+
return blockingStubFunction.apply(channel).withWaitForReady();
130133
}
131134

132135
/**

Diff for: providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/grpc/GrpcResolver.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import io.grpc.Status.Code;
3737
import io.grpc.StatusRuntimeException;
3838
import java.util.Map;
39+
import java.util.concurrent.TimeUnit;
3940
import java.util.function.Consumer;
4041
import java.util.function.Function;
4142

@@ -50,6 +51,7 @@ public final class GrpcResolver implements Resolver {
5051
private final GrpcConnector<ServiceGrpc.ServiceStub, ServiceGrpc.ServiceBlockingStub> connector;
5152
private final Cache cache;
5253
private final ResolveStrategy strategy;
54+
private final FlagdOptions options;
5355

5456
/**
5557
* Resolves flag values using https://buf.build/open-feature/flagd/docs/main:flagd.evaluation.v1.
@@ -63,6 +65,7 @@ public GrpcResolver(
6365
final FlagdOptions options, final Cache cache, final Consumer<FlagdProviderEvent> onProviderEvent) {
6466
this.cache = cache;
6567
this.strategy = ResolveFactory.getStrategy(options);
68+
this.options = options;
6669
this.connector = new GrpcConnector<>(
6770
options,
6871
ServiceGrpc::newStub,
@@ -108,15 +111,15 @@ public void onError() {
108111
public ProviderEvaluation<Boolean> booleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx) {
109112
ResolveBooleanRequest request = ResolveBooleanRequest.newBuilder().buildPartial();
110113

111-
return resolve(key, ctx, request, connector.getResolver()::resolveBoolean, null);
114+
return resolve(key, ctx, request, getResolver()::resolveBoolean, null);
112115
}
113116

114117
/**
115118
* String evaluation from grpc resolver.
116119
*/
117120
public ProviderEvaluation<String> stringEvaluation(String key, String defaultValue, EvaluationContext ctx) {
118121
ResolveStringRequest request = ResolveStringRequest.newBuilder().buildPartial();
119-
return resolve(key, ctx, request, connector.getResolver()::resolveString, null);
122+
return resolve(key, ctx, request, getResolver()::resolveString, null);
120123
}
121124

122125
/**
@@ -125,7 +128,7 @@ public ProviderEvaluation<String> stringEvaluation(String key, String defaultVal
125128
public ProviderEvaluation<Double> doubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) {
126129
ResolveFloatRequest request = ResolveFloatRequest.newBuilder().buildPartial();
127130

128-
return resolve(key, ctx, request, connector.getResolver()::resolveFloat, null);
131+
return resolve(key, ctx, request, getResolver()::resolveFloat, null);
129132
}
130133

131134
/**
@@ -135,8 +138,11 @@ public ProviderEvaluation<Integer> integerEvaluation(String key, Integer default
135138

136139
ResolveIntRequest request = ResolveIntRequest.newBuilder().buildPartial();
137140

138-
return resolve(
139-
key, ctx, request, connector.getResolver()::resolveInt, (Object value) -> ((Long) value).intValue());
141+
return resolve(key, ctx, request, getResolver()::resolveInt, (Object value) -> ((Long) value).intValue());
142+
}
143+
144+
private ServiceGrpc.ServiceBlockingStub getResolver() {
145+
return connector.getResolver().withDeadlineAfter(options.getDeadline(), TimeUnit.MILLISECONDS);
140146
}
141147

142148
/**
@@ -150,7 +156,7 @@ public ProviderEvaluation<Value> objectEvaluation(String key, Value defaultValue
150156
key,
151157
ctx,
152158
request,
153-
connector.getResolver()::resolveObject,
159+
getResolver()::resolveObject,
154160
(Object value) -> convertObjectResponse((Struct) value));
155161
}
156162

Diff for: providers/flagd/test-harness

0 commit comments

Comments
 (0)