Abhishek Bansal
01/29/2020, 3:54 PMSocketTimeOutExceptions
which is fine. I have all my API calls wrapped in try.. catch()
block like this
try {
viewModelScope.launch {
apiService.doCall()
// do other stuff
}
} catch(e: Exception) {}
and in case of flow I am using .catch()
operator for catching exceptions. My problem is my app randomly crashes with crashstack looking like this.
DefaultDispatcher-worker-1
Process: <appId>, PID: 6524
<http://java.net|java.net>.SocketTimeoutException: timeout
at okhttp3.internal.http2.Http2Stream$StreamTimeout.newTimeoutException(Http2Stream.java:677)
at okhttp3.internal.http2.Http2Stream$StreamTimeout.exitAndThrowIfTimedOut(Http2Stream.java:685)
at okhttp3.internal.http2.Http2Stream.takeHeaders(Http2Stream.java:154)
at okhttp3.internal.http2.Http2ExchangeCodec.readResponseHeaders(Http2ExchangeCodec.java:136)
at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.java:115)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:94)
This does not happen with all timeouts but happen at random. It seem like there is something is off with coroutine setup/usage/exception handling. Any pointers will help. Thanks!marstran
01/29/2020, 4:25 PMlaunch
fires off a parallel coroutine. When it throws the error, you have already left the try-catch block.Abhishek Bansal
01/29/2020, 4:28 PM