Hello, I'm using OkHttp (version 4.7.2) in a Gradl...
# squarelibraries
l
Hello, I'm using OkHttp (version 4.7.2) in a Gradle plugin project, and I get
okhttp3.internal.http2.StreamResetException: stream was reset: CANCEL
unless I add logging with
BODY
level:
Copy code
.addInterceptor(HttpLoggingInterceptor(logger = HttpLoggingInterceptor.Logger.DEFAULT)
            .setLevel(HttpLoggingInterceptor.Level.BODY))
Whenever I disable body logging, I get the cryptic exception aforementioned, and I don't get why. Where should I look for? I can commit and push my work for reproducing if needed since its open source.
✔️ 1
g
We have this error on request cancellation
l
Weird… in my case, I'm not doing any cancellation, and it doesn't trigger when body logging is enabled.
@gildor I found something interesting! When I use
execute()
in place of my
await
extension (which most likely looks like yours that is on GitHub), I get no issue!
Here is the apparently problematic extension that I'm using. I'm replacing with
<http://Dispatchers.IO|Dispatchers.IO> { call.execute() }
for now, even though I means giving up on cancellation…
Found another solution for now. Replacing the
finally
block with a
catch
block where I rethrow after cancelling the `Call`:
Copy code
catch (t: Throwable) {
    cancel()
    throw t
}
j
cancelation still works with execute
l
How could it work with execute? It's not a suspending function, so it doesn't have access to the
CancellableContinuation
or the
Job
. Or would it work when its call is wrapped with
runInterruptible { }
?
j
Just call cancel on the Call and it will interrupt the operation
l
Yes, but that's a little more complicated as it assumes there's a non blocked thread to call that
cancel()
function. Anyway, I fixed my
await
extension by not calling
cancel
in all cases (what happened when it was in the
finally
block) (and I feel silly now).
131 Views