1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-17 08:42:25 +03:00

Fix MockWebServer with SPDY on Android.

Fix for issue #1552
Related to commit f78f74f from issue #1294

Before this change:
SpdyConnection creates threads to handle the reading and writing. If
those threads die from a RuntimeException it triggers Android's default
UncaughtExceptionHandler, which kills the test process. Previously exceptions
were being swallowed, but commit f78f74f caused the exceptions to be
propagated.

This change adds extra handling for RuntimeException to stop them escaping.
This commit is contained in:
Neil Fuller
2015-04-14 10:21:29 +01:00
parent b40f99a950
commit fb155c4766

View File

@@ -575,7 +575,7 @@ public final class SpdyConnection implements Closeable {
}
connectionErrorCode = ErrorCode.NO_ERROR;
streamErrorCode = ErrorCode.CANCEL;
} catch (IOException e) {
} catch (RuntimeException | IOException e) {
connectionErrorCode = ErrorCode.PROTOCOL_ERROR;
streamErrorCode = ErrorCode.PROTOCOL_ERROR;
} finally {
@@ -640,8 +640,11 @@ public final class SpdyConnection implements Closeable {
@Override public void execute() {
try {
handler.receive(newStream);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (RuntimeException | IOException e) {
try {
newStream.close(ErrorCode.PROTOCOL_ERROR);
} catch (IOException ignored) {
}
}
}
});