Skip to content

Commit 3df8719

Browse files
Recover from an SSLSocket crash (#1714)
* Recover from an SSLSocket crash See: square/okhttp#9123 * Call InputStream.close() / OutputStream.close() instead --------- Co-authored-by: Jesse Wilson <jwilson@squareup.com>
1 parent d2897ad commit 3df8719

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

okio/src/jvmMain/kotlin/okio/internal/DefaultSocket.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ internal class DefaultSocket(val socket: JavaNetSocket) : Socket {
9292
else -> {
9393
if (socket.isClosed || socket.isOutputShutdown) return // Nothing to do.
9494
outputStream.flush()
95-
socket.shutdownOutput()
95+
try {
96+
socket.shutdownOutput()
97+
} catch (_: UnsupportedOperationException) {
98+
// Android API 21's SSLSocket doesn't implement this! So close the whole socket.
99+
// https://github.com/square/okhttp/issues/9123
100+
outputStream.close()
101+
}
96102
}
97103
}
98104
}
@@ -146,7 +152,13 @@ internal class DefaultSocket(val socket: JavaNetSocket) : Socket {
146152
// Close this stream only.
147153
else -> {
148154
if (socket.isClosed || socket.isInputShutdown) return // Nothing to do.
149-
socket.shutdownInput()
155+
try {
156+
socket.shutdownInput()
157+
} catch (_: UnsupportedOperationException) {
158+
// Android API 21's SSLSocket doesn't implement this! So close the whole socket.
159+
// https://github.com/square/okhttp/issues/9123
160+
inputStream.close()
161+
}
150162
}
151163
}
152164
}

0 commit comments

Comments
 (0)