Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x Http2Connection should ignore a max concurrent streams setting of zero from the client #7346

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,21 @@ public void clientSettings(Http2Settings http2Settings) {

// Set server MAX_CONCURRENT_STREAMS limit when client sends number lower than hard limit
// from configuration. Refuse settings if client sends larger number than is configured.
// If the client sends zero the server MAX_CONCURRENT_STREAMS will not be changed.
this.clientSettings.presentValue(Http2Setting.MAX_CONCURRENT_STREAMS)
.ifPresent(it -> {
if (http2Config.maxConcurrentStreams() >= it) {
maxClientConcurrentStreams = it;
} else {
Http2GoAway frame =
new Http2GoAway(0,
Http2ErrorCode.PROTOCOL,
"Value of maximum concurrent streams limit " + it
+ " exceeded hard limit value "
+ http2Config.maxConcurrentStreams());
connectionWriter.write(frame.toFrameData(clientSettings, 0, Http2Flag.NoFlags.create()));
if (it != 0) {
if (http2Config.maxConcurrentStreams() >= it) {
maxClientConcurrentStreams = it;
} else {
Http2GoAway frame =
new Http2GoAway(0,
Http2ErrorCode.PROTOCOL,
"Value of maximum concurrent streams limit " + it
+ " exceeded hard limit value "
+ http2Config.maxConcurrentStreams());
connectionWriter.write(frame.toFrameData(clientSettings, 0, Http2Flag.NoFlags.create()));
}
}
});
}
Expand Down
5 changes: 5 additions & 0 deletions nima/tests/integration/grpc/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<groupId>io.helidon.nima.grpc</groupId>
<artifactId>helidon-nima-grpc-webserver</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>

<dependency>
<!-- todo required for @Generated -->
<groupId>javax.annotation</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.nima.tests.integration.grpc.webserver;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import io.helidon.nima.grpc.events.Events;
import io.helidon.nima.grpc.webserver.GrpcService;

import com.google.protobuf.Descriptors;
import com.google.protobuf.Empty;
import io.grpc.stub.StreamObserver;

import static io.helidon.nima.grpc.webserver.ResponseHelper.complete;

public class EventService implements GrpcService {

private final List<Listener> listeners = new ArrayList<>();

private final Lock lock = new ReentrantLock();

@Override
public Descriptors.FileDescriptor proto() {
return Events.getDescriptor();
}

@Override
public void update(Routing router) {
router.unary("Send", this::send)
.bidi("Events", this::events);
}

private StreamObserver<Events.EventRequest> events(StreamObserver<Events.EventResponse> responses) {
lock.lock();
try {
Listener listener = new Listener(responses);
listeners.add(listener);
return listener;
} finally {
lock.unlock();
}
}

private void send(Events.Message message, StreamObserver<Empty> observer) {
String text = message.getText();
for (Listener listener : listeners) {
listener.send(text);
}
thegridman marked this conversation as resolved.
Show resolved Hide resolved
complete(observer, Empty.getDefaultInstance());
}

private class Listener
implements StreamObserver<Events.EventRequest> {

private final StreamObserver<Events.EventResponse> responses;

private final Set<Long> subscribers = new HashSet<>();

public Listener(StreamObserver<Events.EventResponse> responses) {
this.responses = responses;
}

public void send(String text) {
for (long id : subscribers) {
responses.onNext(Events.EventResponse.newBuilder()
.setEvent(Events.Event.newBuilder()
.setId(id)
.setText(text).build())
.build());
}
}

@Override
public void onNext(Events.EventRequest request) {
long id = request.getId();
if (request.getAction() == Events.EventRequest.Action.SUBSCRIBE) {
subscribers.add(id);
responses.onNext(Events.EventResponse.newBuilder()
.setSubscribed(Events.Subscribed.newBuilder().setId(id).build())
.build());
} else {
subscribers.remove(id);
}
}

@Override
public void onError(Throwable throwable) {
close();
}

@Override
public void onCompleted() {
close();
}

private void close() {
lock.lock();
try {
subscribers.clear();
listeners.remove(this);
} finally {
lock.unlock();
}
}
}
}
60 changes: 60 additions & 0 deletions nima/tests/integration/grpc/server/src/main/proto/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


syntax = "proto3";
option java_package = "io.helidon.nima.grpc.events";

import "google/protobuf/empty.proto";

service EventService {
rpc Send (Message) returns (google.protobuf.Empty) {}
rpc Events (stream EventRequest) returns (stream EventResponse) {}
}

message Message {
string text = 2;
}

message EventRequest {
int64 id = 1;
enum Action {
SUBSCRIBE = 0;
UNSUBSCRIBE = 1;
}
Action action = 2;
}

message EventResponse {
oneof response_type {
Subscribed subscribed = 1;
Unsubscribed unsubscribed = 2;
Event event = 3;
}
}

message Subscribed {
int64 id = 1;
}

message Unsubscribed {
int64 id = 1;
}

message Event {
int64 id = 1;
string text = 2;
}