Skip to content

Commit c319b79

Browse files
authored
Create an HTTP/2 stream using the initial HTTP/2 settings from config. Note that the connection settings may not be negotiated at this time, so they cannot be used. (#10814)
1 parent 69a754a commit c319b79

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

webclient/grpc/src/main/java/io/helidon/webclient/grpc/GrpcBaseClientCall.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import io.helidon.http.WritableHeaders;
3939
import io.helidon.http.http2.Http2FrameData;
4040
import io.helidon.http.http2.Http2Headers;
41+
import io.helidon.http.http2.Http2Setting;
4142
import io.helidon.http.http2.Http2Settings;
4243
import io.helidon.http.http2.Http2StreamState;
4344
import io.helidon.metrics.api.Counter;
@@ -57,6 +58,7 @@
5758
import io.helidon.webclient.http2.Http2Client;
5859
import io.helidon.webclient.http2.Http2ClientConnection;
5960
import io.helidon.webclient.http2.Http2ClientImpl;
61+
import io.helidon.webclient.http2.Http2ClientProtocolConfig;
6062
import io.helidon.webclient.http2.Http2StreamConfig;
6163
import io.helidon.webclient.http2.StreamTimeoutException;
6264

@@ -84,10 +86,12 @@ abstract class GrpcBaseClientCall<ReqT, ResT> extends ClientCall<ReqT, ResT> {
8486
protected static final BufferData EMPTY_BUFFER_DATA = BufferData.empty();
8587
protected static final int DATA_PREFIX_LENGTH = 5;
8688
protected static final Tag OK_TAG = Tag.create("grpc.status", "OK");
89+
8790
protected record MethodMetrics(Counter callStarted,
8891
Timer callDuration,
8992
DistributionSummary sentMessageSize,
9093
DistributionSummary recvMessageSize) { }
94+
9195
private static final LazyValue<Map<String, MethodMetrics>> METHOD_METRICS = LazyValue.create(ConcurrentHashMap::new);
9296

9397
private final GrpcClientImpl grpcClient;
@@ -151,10 +155,16 @@ public void start(Listener<ResT> responseListener, Metadata metadata) {
151155
connection = Http2ClientConnection.create((Http2ClientImpl) grpcClient.http2Client(),
152156
clientConnection, true);
153157

158+
// note that settings from connection may not be initialized at this time
159+
// given that Http2ClientConnection.create() above runs asynchronously
160+
Http2Settings http2Settings = http2Settings(grpcClient.http2Client()
161+
.prototype()
162+
.protocolConfig());
163+
154164
// create HTTP2 stream from connection
155165
clientStream = new GrpcClientStream(
156166
connection,
157-
Http2Settings.create(), // Http2Settings
167+
http2Settings,
158168
socket, // SocketContext
159169
new Http2StreamConfig() {
160170
@Override
@@ -169,8 +179,8 @@ public int priority() {
169179

170180
@Override
171181
public Duration readTimeout() {
172-
return grpcClient.prototype().readTimeout().orElse(
173-
grpcClient.prototype().protocolConfig().pollWaitTime());
182+
GrpcClientConfig config = grpcClient.prototype();
183+
return config.readTimeout().orElse(config.protocolConfig().pollWaitTime());
174184
}
175185
},
176186
null, // Http2ClientConfig
@@ -389,6 +399,17 @@ protected void handleStreamTimeout(StreamTimeoutException e) {
389399
socket().log(LOGGER, TRACE, "[Reading thread] HTTP/2 stream timeout, retrying");
390400
}
391401

402+
private Http2Settings http2Settings(Http2ClientProtocolConfig config) {
403+
Http2Settings.Builder b = Http2Settings.builder();
404+
if (config.maxHeaderListSize() > 0) {
405+
b.add(Http2Setting.MAX_HEADER_LIST_SIZE, config.maxHeaderListSize());
406+
}
407+
return b.add(Http2Setting.INITIAL_WINDOW_SIZE, (long) config.initialWindowSize())
408+
.add(Http2Setting.MAX_FRAME_SIZE, (long) config.maxFrameSize())
409+
.add(Http2Setting.ENABLE_PUSH, false)
410+
.build();
411+
}
412+
392413
protected void initMetrics() {
393414
String baseUri = grpcChannel.baseUri().toString();
394415
String methodName = methodDescriptor.getFullMethodName();

0 commit comments

Comments
 (0)