From fb155c47661ede5da395dfb4e620867263b8c8e7 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Tue, 14 Apr 2015 10:21:29 +0100 Subject: [PATCH] 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. --- .../squareup/okhttp/internal/spdy/SpdyConnection.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/spdy/SpdyConnection.java b/okhttp/src/main/java/com/squareup/okhttp/internal/spdy/SpdyConnection.java index 04bff0bad..3edb94ca5 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/internal/spdy/SpdyConnection.java +++ b/okhttp/src/main/java/com/squareup/okhttp/internal/spdy/SpdyConnection.java @@ -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) { + } } } });