-
Workaround for OkHttp Interrupt issues. · 0f502b2a
Relates to https://github.com/square/okhttp/issues/3146. This was from https://github.com/androidx/media/pull/71. There is a draft PR https://github.com/square/okhttp/pull/7185/files which documents OkHttp's ideal handling of cancellation including interrupts. But a few key points 1) This is a target state, and OkHttp does not currently handle interrupts correctly. In the past this has been identified, and the advice is to avoid interrupts on Http threads, see discussion on https://github.com/square/okhttp/issues/1902. Also an attempt at a fix here https://github.com/square/okhttp/pull/7023 which wasn't in a form to land. 2) Even with this fixed, it is likely to never be optimal, because of OkHttp sharing a socket connection for multiple inflight requests. From https://github.com/square/okhttp/pull/7185 ``` Thread.interrupt() is Clumsy ---------------------------- `Thread.interrupt()` is Java's built-in mechanism to cancel an in-flight `Thread`, regardless of what work it's currently performing. We recommend against using `Thread.interrupt()` with OkHttp because it may disrupt shared resources including HTTP/2 connections and cache files. In particular, calling `Thread.interrupt()` may cause unrelated threads' call to fail with an `IOException`. ``` This PR leaves the Loader/DataSource thread parked on a countdown latch, while this may seem wasteful and an additional context switch. However in practice the response isn't returned until the Http2Connection and Http2Reader have a response from the server and these means effectively parking in a `wait()` statement here https://github.com/square/okhttp/blob/9e039e94123defbfd5f11dc64ae146c46b7230eb/okhttp/src/jvmMain/kotlin/okhttp3/internal/http2/Http2Stream.kt#L140 PiperOrigin-RevId: 446652468
yschimke committed
| Name |
Last commit
|
Last Update |
|---|---|---|
| .. | ||
| av1 | Loading commit data... | |
| cast | Loading commit data... | |
| cronet | Loading commit data... | |
| ffmpeg | Loading commit data... | |
| flac | Loading commit data... | |
| ima | Loading commit data... | |
| leanback | Loading commit data... | |
| media2 | Loading commit data... | |
| mediasession | Loading commit data... | |
| okhttp | Loading commit data... | |
| opus | Loading commit data... | |
| rtmp | Loading commit data... | |
| vp9 | Loading commit data... | |
| workmanager | Loading commit data... | |
| README.md | Loading commit data... |