mirror of https://github.com/grpc/grpc-java.git
Add rst error detail in OkHttp
This commit is contained in:
parent
7d889b6911
commit
0ed059a408
|
|
@ -224,8 +224,7 @@ class NettyClientHandler extends AbstractNettyHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private void onHeadersRead(int streamId, Http2Headers headers, boolean endStream)
|
||||
throws Http2Exception {
|
||||
private void onHeadersRead(int streamId, Http2Headers headers, boolean endStream) {
|
||||
NettyClientStream stream = clientStream(requireHttp2Stream(streamId));
|
||||
stream.transportHeadersReceived(headers, endStream);
|
||||
}
|
||||
|
|
@ -233,7 +232,7 @@ class NettyClientHandler extends AbstractNettyHandler {
|
|||
/**
|
||||
* Handler for an inbound HTTP/2 DATA frame.
|
||||
*/
|
||||
private void onDataRead(int streamId, ByteBuf data, boolean endOfStream) throws Http2Exception {
|
||||
private void onDataRead(int streamId, ByteBuf data, boolean endOfStream) {
|
||||
NettyClientStream stream = clientStream(requireHttp2Stream(streamId));
|
||||
stream.transportDataReceived(data, endOfStream);
|
||||
}
|
||||
|
|
@ -241,10 +240,11 @@ class NettyClientHandler extends AbstractNettyHandler {
|
|||
/**
|
||||
* Handler for an inbound HTTP/2 RST_STREAM frame, terminating a stream.
|
||||
*/
|
||||
private void onRstStreamRead(int streamId, long errorCode) throws Http2Exception {
|
||||
private void onRstStreamRead(int streamId, long errorCode) {
|
||||
NettyClientStream stream = clientStream(connection().stream(streamId));
|
||||
if (stream != null) {
|
||||
Status status = GrpcUtil.Http2Error.statusForCode((int) errorCode);
|
||||
Status status = GrpcUtil.Http2Error.statusForCode((int) errorCode)
|
||||
.augmentDescription("Received Rst Stream");
|
||||
stream.transportReportStatus(status, false /*stop delivery*/, new Metadata());
|
||||
}
|
||||
}
|
||||
|
|
@ -500,6 +500,7 @@ class NettyClientHandler extends AbstractNettyHandler {
|
|||
|
||||
private Status statusFromGoAway(long errorCode, byte[] debugData) {
|
||||
Status status = GrpcUtil.Http2Error.statusForCode((int) errorCode);
|
||||
status.augmentDescription("Received Goaway");
|
||||
if (debugData != null && debugData.length > 0) {
|
||||
// If a debug message was provided, use it.
|
||||
String msg = new String(debugData, UTF_8);
|
||||
|
|
|
|||
|
|
@ -480,9 +480,13 @@ class OkHttpClientTransport implements ManagedClientTransport {
|
|||
/**
|
||||
* Finish all active streams due to an IOException, then close the transport.
|
||||
*/
|
||||
void onException(Throwable failureCause) {
|
||||
log.log(Level.WARNING, "Transport failed", failureCause);
|
||||
startGoAway(0, Status.UNAVAILABLE.withCause(failureCause));
|
||||
void onException(Throwable cause) {
|
||||
log.log(Level.WARNING, "Transport failed", cause);
|
||||
Status status = Status.UNAVAILABLE.withCause(cause);
|
||||
if (cause != null) {
|
||||
status = status.augmentDescription("No provided cause");
|
||||
}
|
||||
startGoAway(0, status);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -721,7 +725,7 @@ class OkHttpClientTransport implements ManagedClientTransport {
|
|||
|
||||
@Override
|
||||
public void rstStream(int streamId, ErrorCode errorCode) {
|
||||
finishStream(streamId, toGrpcStatus(errorCode), null);
|
||||
finishStream(streamId, toGrpcStatus(errorCode).augmentDescription("Rst Stream"), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -782,6 +786,7 @@ class OkHttpClientTransport implements ManagedClientTransport {
|
|||
@Override
|
||||
public void goAway(int lastGoodStreamId, ErrorCode errorCode, ByteString debugData) {
|
||||
Status status = GrpcUtil.Http2Error.statusForCode(errorCode.httpCode);
|
||||
status.augmentDescription("Received Goaway");
|
||||
if (debugData != null && debugData.size() > 0) {
|
||||
// If a debug message was provided, use it.
|
||||
status.augmentDescription(debugData.utf8());
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
package io.grpc.okhttp;
|
||||
|
||||
import static com.google.common.base.Charsets.UTF_8;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static io.grpc.Status.Code.INTERNAL;
|
||||
import static io.grpc.internal.GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
|
||||
import static io.grpc.okhttp.Headers.CONTENT_TYPE_HEADER;
|
||||
|
|
@ -68,6 +69,7 @@ import io.grpc.Metadata;
|
|||
import io.grpc.MethodDescriptor;
|
||||
import io.grpc.MethodDescriptor.MethodType;
|
||||
import io.grpc.Status;
|
||||
import io.grpc.Status.Code;
|
||||
import io.grpc.StatusException;
|
||||
import io.grpc.internal.AbstractStream;
|
||||
import io.grpc.internal.ClientStreamListener;
|
||||
|
|
@ -382,7 +384,9 @@ public class OkHttpClientTransportTest {
|
|||
assertContainStream(3);
|
||||
frameHandler().rstStream(3, ErrorCode.PROTOCOL_ERROR);
|
||||
listener.waitUntilStreamClosed();
|
||||
assertEquals(OkHttpClientTransport.toGrpcStatus(ErrorCode.PROTOCOL_ERROR), listener.status);
|
||||
|
||||
assertThat(listener.status.getDescription()).contains("Rst Stream");
|
||||
assertThat(listener.status.getCode()).isEqualTo(Code.INTERNAL);
|
||||
shutdownAndVerify();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue