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

OutOfMemoryError: Failed to allocate a 8208 byte allocation with 3418760 free byte #1068

Open
liangjingkanji opened this issue Jul 2, 2023 · 8 comments
Assignees

Comments

@liangjingkanji
Copy link

✍️ Describe the bug

Downloading large files (over 150mb) crashes, I'm sure it's Chucker's problem

Exception

Throwing OutOfMemoryError "Failed to allocate a 32 byte allocation with 4673640 free bytes and 4564KB until OOM, target footprint 268435456, growth limit 268435456; failed due to fragmentation (largest possible contiguous allocation 0 bytes). Number of 256KB sized free regions are: 0" (VmSize 6440568 kB, recursive case)

Use

if (BuildConfig.DEBUG) {
    addInterceptor(
        ChuckerInterceptor.Builder(this@App)
            .collector(ChuckerCollector(this@App))
            .maxContentLength(250000L)
            .redactHeaders(emptySet())
            .alwaysReadResponseBody(false)
            .build()
    )
}

💣 Steps to reproduce

  1. Clone https://github.com/liangjingkanji/Net/tree/debug
  2. installing - Runing
  3. Wait for the download to be about 150mb
  4. Crash

🔧 Expected behavior

Do not crash when downloading large files

📷 Screenshots

image image

📱 Tech info

  • Device: Android Simulator
  • OS: Android 13
  • Chucker version: 3.5.2

📄 Additional context

I've recommended your project to others a long time ago

@cortinico
Copy link
Member

Downloading large files (over 150mb) crashes, I'm sure it's Chucker's problem

Can we get a reproducer of some sorts?

@liangjingkanji
Copy link
Author

liangjingkanji commented Jul 16, 2023

What do you mean? You can reproduce the problem by running the demo

I have deleted irrelevant content

@cortinico
Copy link
Member

Thanks for the repro @liangjingkanji
Yes I was able to reproduce with it. I'll look into it and try whenever I'll find time

@liangjingkanji
Copy link
Author

I think this method returns wrong result
com.chuckerteam.chucker.internal.support.IOUtils#isPlaintext

ChuckerInterceptor will try to parse the binary, For example application/octet-stream

@cortinico
Copy link
Member

I think this method returns wrong result
com.chuckerteam.chucker.internal.support.IOUtils#isPlaintext

Yup that could be the reason.
Still you could have a 100Mb JSON response and Chucker will fail with a similar reason

@liangjingkanji
Copy link
Author

liangjingkanji commented Jul 30, 2023

It also fails if I upload the InputStream, Because the ChuckerInterceptor attempt will cause call RequestBody.writeTo

fun InputStream.toRequestBody(
    contentType: MediaType? = MediaConst.OCTET_STREAM,
    contentLength: Long? = null
): RequestBody {
    return object : RequestBody() {
        override fun contentType() = contentType

        val availableLength: Long by lazy {
            if (contentLength != null) return@lazy contentLength
            val availableLength = available()
            if (availableLength == 0) -1L else availableLength.toLong()
        }

        override fun contentLength(): Long {
            return availableLength
        }

        override fun writeTo(sink: BufferedSink) {
            source().use { source ->
                sink.writeAll(source)
            }
        }
    }
}

@cortinico
Copy link
Member

@liangjingkanji is this somethign you'll be up for attempting to fix?

@liangjingkanji
Copy link
Author

Ok, I'll attempting to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants