Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

okhttp3.RequestBody.Companion#gzip throws java.lang.IllegalStateException: closed if used in MultipartBody #7692

Open
korniltsev opened this issue Feb 13, 2023 · 1 comment
Labels
bug Bug in existing code
Milestone

Comments

@korniltsev
Copy link

Reproducer . Tried it on 5.0.0-alpha.11

I believe I can workaround it in our project locally by creating a vendored copy of GzipSink which does not close upstream sink but flushes it with some help of ugly dirty java tricks accessing kotlin internals it should work but it would be nice to be able to use the original extension method in MultipartBody

Stacktrace:

Exception in thread "main" java.lang.IllegalStateException: closed at okio.RealBufferedSink.write(RealBufferedSink.kt:176) at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.kt:162) at okhttp3.MultipartBody.writeTo(MultipartBody.kt:99) at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:64) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:84) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:65) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:205) at okhttp3.internal.connection.RealCall.execute(RealCall.kt:158) at MainKt.main(Main.kt:22)
@korniltsev korniltsev added the bug Bug in existing code label Feb 13, 2023
@yschimke
Copy link
Collaborator

Thanks, copying the reproducer here as it looks quite straight forward

    val client = OkHttpClient()

    val body = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addPart("part1".toRequestBody().gzip())
        .addPart("part2".toRequestBody().gzip())
        .build()

    val req = Request.Builder()
        .post(body)
        .url("http://localhost:4040/ingest")
        .build()

@swankjesse swankjesse added this to the 5.0 milestone Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests

3 participants