customizable-okhttp-logging-interceptor icon indicating copy to clipboard operation
customizable-okhttp-logging-interceptor copied to clipboard

Potential OOM issue when buffer?

Open zmes50416 opened this issue 3 years ago • 4 comments

https://github.com/bartek-wesolowski/customizable-okhttp-logging-interceptor/blob/05f13c021e2657a3f66f2852ef38a3b6fd5877b2/src/main/kotlin/com/bartoszwesolowski/okhttp3/logging/CustomizableHttpLoggingInterceptor.kt#L156

I see this line still read entire body to buffer. so I think this will cause OutOfMemoryError if body is big enough. (not tested yet) Can we change it to maxBodyLength? But I think this will bring another issue with gzip content.

zmes50416 avatar May 26 '22 04:05 zmes50416

Thank you for the suggestion. I'll think about changing this, although, in fact, it might cause more issues with compressed content and displaying correct content length. If your responses contain hundreds of megabytes of data then you should probably not log them at all.

bartek-wesolowski avatar May 31 '22 06:05 bartek-wesolowski

val buffer = Buffer()

requestBody.writeTo(buffer)

When uploading 1g files, the memory is full, and anr occurs.

Debugging found stuck in this line of code.

imcloud avatar Aug 16 '22 05:08 imcloud

@imcloud ANRs don't occur because of full memory. They occur because of long running operations on the main thread. Are you sure you're not running your request on the main thread?

Your case seems to be very specific and I'm not sure if it would be the best idea to add this feature for everyone. It might be best for you to just copy the code of CustomizableHttpLoggingInterceptor (it's just one class) and customize it even more to skip logging some request bodies for specific requests or skip logging request bodies when they have a certain content type.

bartek-wesolowski avatar Aug 16 '22 19:08 bartek-wesolowski

Thank you for your reply.Yes, I have skiped logging when uploading a file

imcloud avatar Aug 22 '22 06:08 imcloud