okhttp: Call onError for IOException thrown by FrameReader.nextFrame().

Since OkHttp wraps many protocol error as IOException, we need to send GoAway for such errors.

Fixes #487
This commit is contained in:
Xudong Ma 2015-05-29 10:21:52 -07:00
parent 0782c0408d
commit eed8f923af
2 changed files with 6 additions and 4 deletions

View File

@ -493,7 +493,9 @@ public class OkHttpClientTransport implements ClientTransport {
while (frameReader.nextFrame(this)) { while (frameReader.nextFrame(this)) {
} }
} catch (IOException ioe) { } catch (IOException ioe) {
onIoException(ioe); // We call onError instead of onIoException here, because OkHttp wraps many protocol errors
// as IOException, we should send GoAway for such errors.
onError(ErrorCode.PROTOCOL_ERROR, ioe.getMessage());
} finally { } finally {
try { try {
frameReader.close(); frameReader.close();

View File

@ -162,9 +162,9 @@ public class OkHttpClientTransportTest {
listener2.waitUntilStreamClosed(); listener2.waitUntilStreamClosed();
assertEquals(0, streams.size()); assertEquals(0, streams.size());
assertEquals(Status.INTERNAL.getCode(), listener1.status.getCode()); assertEquals(Status.INTERNAL.getCode(), listener1.status.getCode());
assertEquals(NETWORK_ISSUE_MESSAGE, listener2.status.getCause().getMessage()); assertEquals("Protocol error\n" + NETWORK_ISSUE_MESSAGE, listener1.status.getDescription());
assertEquals(Status.INTERNAL.getCode(), listener1.status.getCode()); assertEquals(Status.INTERNAL.getCode(), listener2.status.getCode());
assertEquals(NETWORK_ISSUE_MESSAGE, listener2.status.getCause().getMessage()); assertEquals("Protocol error\n" + NETWORK_ISSUE_MESSAGE, listener2.status.getDescription());
verify(transportListener).transportShutdown(); verify(transportListener).transportShutdown();
verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated(); verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
} }