Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
  • Loading branch information
ran-su committed Oct 23, 2024
1 parent 7de2450 commit 396d5a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
10 changes: 5 additions & 5 deletions netty/src/main/java/io/grpc/netty/NettyClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,11 @@ private void onHeadersRead(int streamId, Http2Headers headers, boolean endStream
h2HeadersSize, softLimitHeaderListSize, maxHeaderListSize);
if (shouldFail && endStream) {
stream.transportReportStatus(Status.RESOURCE_EXHAUSTED
.withDescription(
String.format(
"Server Status + Trailers of size %d exceeded Metadata size soft limit: %d",
h2HeadersSize,
softLimitHeaderListSize)), true, new Metadata());
.withDescription(
String.format(
"Server Status + Trailers of size %d exceeded Metadata size soft limit: %d",
h2HeadersSize,
softLimitHeaderListSize)), true, new Metadata());
} else if (shouldFail) {
stream.transportReportStatus(Status.RESOURCE_EXHAUSTED
.withDescription(
Expand Down
23 changes: 13 additions & 10 deletions netty/src/test/java/io/grpc/netty/NettyClientHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,27 +218,30 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
ByteBuf serializedSettings = serializeSettings(new Http2Settings());
channelRead(serializedSettings);
}

@Test
@SuppressWarnings("InlineMeInliner")
public void sendLargerThanSoftLimitHeaderMayFail() throws Exception {
createStream();
// total head size of 7999, soft limit = 2000 and max = 8000. This header has 5999/6000 chance to be rejected.
Http2Headers headers = new DefaultHttp2Headers()
.scheme(HTTPS)
.authority(as("www.fake.com"))
.path(as("/fakemethod"))
.method(HTTP_METHOD)
.add(as("auth"), as("sometoken"))
.add(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC)
.add(TE_HEADER, TE_TRAILERS)
.add("large-field", Strings.repeat("a", 7620));
.scheme(HTTPS)
.authority(as("www.fake.com"))
.path(as("/fakemethod"))
.method(HTTP_METHOD)
.add(as("auth"), as("sometoken"))
.add(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC)
.add(TE_HEADER, TE_TRAILERS)
.add("large-field", Strings.repeat("a", 7620));

ByteBuf headersFrame = headersFrame(STREAM_ID, headers);
channelRead(headersFrame);
ArgumentCaptor<Status> statusArgumentCaptor = ArgumentCaptor.forClass(Status.class);
verify(streamListener).closed(statusArgumentCaptor.capture(), eq(PROCESSED), any(Metadata.class));
verify(streamListener).closed(statusArgumentCaptor.capture(), eq(PROCESSED),
any(Metadata.class));
assertThat(statusArgumentCaptor.getValue().getCode()).isEqualTo(Status.Code.RESOURCE_EXHAUSTED);
assertThat(statusArgumentCaptor.getValue().getDescription()).contains("exceeded Metadata size soft limit");
assertThat(statusArgumentCaptor.getValue().getDescription()).contains(
"exceeded Metadata size soft limit");
}

@Test
Expand Down

0 comments on commit 396d5a2

Please sign in to comment.