netty: Upgrade to 4.1.6 and tcnative Fork23. Fixes #2224 (#2349)

This commit is contained in:
Jakob Buchgraber 2016-10-20 00:24:58 +02:00 committed by GitHub
parent 10f4c90f4e
commit 6fa63a6371
5 changed files with 47 additions and 86 deletions

View File

@ -62,7 +62,7 @@ In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven-
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>1.1.33.Fork19</version>
<version>1.1.33.Fork23</version>
</dependency>
</dependencies>
</project>
@ -80,7 +80,7 @@ buildscript {
}
dependencies {
compile 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork19'
compile 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork23'
}
```
@ -115,7 +115,7 @@ In Maven, you can use the [os-maven-plugin](https://github.com/trustin/os-maven-
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative</artifactId>
<version>1.1.33.Fork19</version>
<version>1.1.33.Fork23</version>
<classifier>${tcnative.classifier}</classifier>
</dependency>
</dependencies>
@ -183,7 +183,7 @@ if (osdetector.os == "linux" && osdetector.release.isLike("fedora")) {
}
dependencies {
compile 'io.netty:netty-tcnative:1.1.33.Fork19:' + tcnative_classifier
compile 'io.netty:netty-tcnative:1.1.33.Fork23:' + tcnative_classifier
}
```

View File

@ -161,9 +161,9 @@ subprojects {
protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.8.0',
protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
netty: 'io.netty:netty-codec-http2:[4.1.4.Final]',
netty_epoll: 'io.netty:netty-transport-native-epoll:4.1.4.Final' + epoll_suffix,
netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork19',
netty: 'io.netty:netty-codec-http2:[4.1.6.Final]',
netty_epoll: 'io.netty:netty-transport-native-epoll:4.1.6.Final' + epoll_suffix,
netty_tcnative: 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork23',
// Test dependencies.
junit: 'junit:junit:4.11',

View File

@ -49,9 +49,6 @@ package io.grpc.netty;
import static com.google.common.base.Charsets.US_ASCII;
import static com.google.common.base.Preconditions.checkArgument;
import static io.grpc.netty.Utils.TE_HEADER;
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_HEADER_TABLE_SIZE;
import static io.netty.handler.codec.http2.Http2Error.COMPRESSION_ERROR;
import static io.netty.handler.codec.http2.Http2Error.ENHANCE_YOUR_CALM;
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
import static io.netty.handler.codec.http2.Http2Exception.connectionError;
import static io.netty.util.AsciiString.isUpperCase;
@ -69,7 +66,6 @@ import io.netty.handler.codec.http2.internal.hpack.Decoder;
import io.netty.util.AsciiString;
import io.netty.util.internal.PlatformDependent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -85,16 +81,16 @@ abstract class GrpcHttp2HeadersDecoder implements Http2HeadersDecoder,
private static final float HEADERS_COUNT_WEIGHT_NEW = 1 / 5f;
private static final float HEADERS_COUNT_WEIGHT_HISTORICAL = 1 - HEADERS_COUNT_WEIGHT_NEW;
private final int maxHeaderSize;
private final Decoder decoder;
private final Http2HeaderTable headerTable;
private final Decoder decoder = new Decoder();
private final Http2HeaderTable headerTable = new GrpcHttp2HeaderTable();
private float numHeadersGuess = 8;
GrpcHttp2HeadersDecoder(int maxHeaderSize) {
this.maxHeaderSize = maxHeaderSize;
decoder = new Decoder(maxHeaderSize, DEFAULT_HEADER_TABLE_SIZE, 32);
headerTable = new GrpcHttp2HeaderTable();
GrpcHttp2HeadersDecoder(long maxHeaderListSize) {
try {
decoder.setMaxHeaderListSize(maxHeaderListSize);
} catch (Http2Exception e) {
PlatformDependent.throwException(e);
}
}
@Override
@ -103,100 +99,65 @@ abstract class GrpcHttp2HeadersDecoder implements Http2HeadersDecoder,
}
@Override
public int maxHeaderSize() {
return maxHeaderSize;
}
public Http2Headers decodeHeaders(int streamId, ByteBuf headerBlock) throws Http2Exception {
GrpcHttp2InboundHeaders headers = newHeaders(1 + (int) numHeadersGuess);
decoder.decode(streamId, headerBlock, headers);
@Override
public Http2Headers decodeHeaders(ByteBuf headerBlock) throws Http2Exception {
try {
GrpcHttp2InboundHeaders headers = newHeaders(1 + (int) numHeadersGuess);
decoder.decode(headerBlock, headers);
if (decoder.endHeaderBlock()) {
maxHeaderSizeExceeded();
}
numHeadersGuess = HEADERS_COUNT_WEIGHT_NEW * headers.numHeaders()
+ HEADERS_COUNT_WEIGHT_HISTORICAL * numHeadersGuess;
numHeadersGuess = HEADERS_COUNT_WEIGHT_NEW * headers.numHeaders()
+ HEADERS_COUNT_WEIGHT_HISTORICAL * numHeadersGuess;
return headers;
} catch (IOException e) {
throw connectionError(COMPRESSION_ERROR, e, e.getMessage());
}
return headers;
}
abstract GrpcHttp2InboundHeaders newHeaders(int numHeadersGuess);
/**
* Respond to headers block resulting in the maximum header size being exceeded.
* @throws Http2Exception If we can not recover from the truncation.
*/
private void maxHeaderSizeExceeded() throws Http2Exception {
throw connectionError(ENHANCE_YOUR_CALM, "Header size exceeded max allowed bytes (%d)",
maxHeaderSize);
}
@Override
public Configuration configuration() {
return this;
}
private final class GrpcHttp2HeaderTable implements Http2HeaderTable {
private int maxHeaderListSize = Integer.MAX_VALUE;
@Override
public void maxHeaderTableSize(int max) throws Http2Exception {
if (max < 0) {
throw connectionError(PROTOCOL_ERROR, "Header Table Size must be non-negative but was %d",
max);
}
try {
decoder.setMaxHeaderTableSize(max);
} catch (Throwable t) {
throw connectionError(PROTOCOL_ERROR, t.getMessage(), t);
}
public void maxHeaderTableSize(long max) throws Http2Exception {
decoder.setMaxHeaderTableSize(max);
}
@Override
public int maxHeaderTableSize() {
public long maxHeaderTableSize() {
return decoder.getMaxHeaderTableSize();
}
@Override
public void maxHeaderListSize(int max) throws Http2Exception {
if (max < 0) {
// Over 2^31 - 1 (minus in integer) size is set to the maximun value
maxHeaderListSize = Integer.MAX_VALUE;
} else {
maxHeaderListSize = max;
}
public void maxHeaderListSize(long max) throws Http2Exception {
decoder.setMaxHeaderListSize(max);
}
@Override
public int maxHeaderListSize() {
return maxHeaderListSize;
public long maxHeaderListSize() {
return decoder.getMaxHeaderListSize();
}
}
static final class GrpcHttp2ServerHeadersDecoder extends GrpcHttp2HeadersDecoder {
GrpcHttp2ServerHeadersDecoder(int maxHeaderSize) {
super(maxHeaderSize);
GrpcHttp2ServerHeadersDecoder(long maxHeaderListSize) {
super(maxHeaderListSize);
}
@Override GrpcHttp2InboundHeaders newHeaders(int numHeadersGuess) {
@Override
GrpcHttp2InboundHeaders newHeaders(int numHeadersGuess) {
return new GrpcHttp2RequestHeaders(numHeadersGuess);
}
}
static final class GrpcHttp2ClientHeadersDecoder extends GrpcHttp2HeadersDecoder {
GrpcHttp2ClientHeadersDecoder(int maxHeaderSize) {
super(maxHeaderSize);
GrpcHttp2ClientHeadersDecoder(long maxHeaderListSize) {
super(maxHeaderListSize);
}
@Override GrpcHttp2InboundHeaders newHeaders(int numHeadersGuess) {
@Override
GrpcHttp2InboundHeaders newHeaders(int numHeadersGuess) {
return new GrpcHttp2ResponseHeaders(numHeadersGuess);
}
}

View File

@ -31,7 +31,7 @@
package io.grpc.netty;
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_HEADER_TABLE_SIZE;
import static io.grpc.internal.GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE;
import static io.netty.util.AsciiString.of;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
@ -70,9 +70,9 @@ public class GrpcHttp2HeadersDecoderTest {
@Test
public void decode_requestHeaders() throws Http2Exception {
Http2HeadersDecoder decoder = new GrpcHttp2ServerHeadersDecoder(8192);
Http2HeadersDecoder decoder = new GrpcHttp2ServerHeadersDecoder(DEFAULT_MAX_HEADER_LIST_SIZE);
Http2HeadersEncoder encoder =
new DefaultHttp2HeadersEncoder(DEFAULT_HEADER_TABLE_SIZE, NEVER_SENSITIVE);
new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
Http2Headers headers = new DefaultHttp2Headers(false);
headers.add(of(":scheme"), of("https")).add(of(":method"), of("GET"))
@ -81,7 +81,7 @@ public class GrpcHttp2HeadersDecoderTest {
ByteBuf encodedHeaders = ReferenceCountUtil.releaseLater(Unpooled.buffer());
encoder.encodeHeaders(headers, encodedHeaders);
Http2Headers decodedHeaders = decoder.decodeHeaders(encodedHeaders);
Http2Headers decodedHeaders = decoder.decodeHeaders(3 /* randomly chosen */, encodedHeaders);
assertEquals(headers.get(of(":scheme")), decodedHeaders.scheme());
assertEquals(headers.get(of(":method")), decodedHeaders.method());
assertEquals(headers.get(of(":path")), decodedHeaders.path());
@ -99,16 +99,16 @@ public class GrpcHttp2HeadersDecoderTest {
@Test
public void decode_responseHeaders() throws Http2Exception {
Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(8192);
Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(DEFAULT_MAX_HEADER_LIST_SIZE);
Http2HeadersEncoder encoder =
new DefaultHttp2HeadersEncoder(DEFAULT_HEADER_TABLE_SIZE, NEVER_SENSITIVE);
new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
Http2Headers headers = new DefaultHttp2Headers(false);
headers.add(of(":status"), of("200")).add(of("custom"), of("header"));
ByteBuf encodedHeaders = ReferenceCountUtil.releaseLater(Unpooled.buffer());
encoder.encodeHeaders(headers, encodedHeaders);
Http2Headers decodedHeaders = decoder.decodeHeaders(encodedHeaders);
Http2Headers decodedHeaders = decoder.decodeHeaders(3 /* randomly chosen */, encodedHeaders);
assertEquals(headers.get(of(":status")), decodedHeaders.get(of(":status")));
assertEquals(headers.get(of("custom")), decodedHeaders.get(of("custom")));
assertEquals(headers.size(), decodedHeaders.size());
@ -122,12 +122,12 @@ public class GrpcHttp2HeadersDecoderTest {
public void decode_emptyHeaders() throws Http2Exception {
Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(8192);
Http2HeadersEncoder encoder =
new DefaultHttp2HeadersEncoder(DEFAULT_HEADER_TABLE_SIZE, NEVER_SENSITIVE);
new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
ByteBuf encodedHeaders = ReferenceCountUtil.releaseLater(Unpooled.buffer());
encoder.encodeHeaders(new DefaultHttp2Headers(false), encodedHeaders);
Http2Headers decodedHeaders = decoder.decodeHeaders(encodedHeaders);
Http2Headers decodedHeaders = decoder.decodeHeaders(3 /* randomly chosen */, encodedHeaders);
assertEquals(0, decodedHeaders.size());
assertThat(decodedHeaders.toString(), containsString("[]"));
}

View File

@ -284,8 +284,8 @@ public class NettyClientTransportTest {
+ " size limit!");
} catch (Exception e) {
Throwable rootCause = getRootCause(e);
assertTrue(rootCause.getMessage(),
rootCause.getMessage().contains("Header size exceeded max allowed size (1)"));
assertTrue(rootCause instanceof StatusException);
assertEquals(Status.INTERNAL.getCode(), ((StatusException) rootCause).getStatus().getCode());
}
}