Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

PicoHTTP#collectLines throws OutOfMemoryError when reading a file #2

Open
Minemobs opened this issue Apr 16, 2023 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@Minemobs
Copy link
Member

When a file is sent to a route, the binary data is sent after the headers, but if the file is too big, then the collectLines throws a OutOfMemoryError.
The size of the file could be checked by reading the Content-Length header, but still, I don't believe that it should use that much heap.
StackTrace:

TestHTTP > testFile() STANDARD_ERROR
    java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
        at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
        at net.thesimpleteam.picohttp.PicoHTTP.listenForRequests(PicoHTTP.java:159)
        at net.thesimpleteam.picohttp.PicoHTTP.lambda$run$6(PicoHTTP.java:114)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
    Caused by: java.lang.OutOfMemoryError: Java heap space
        at java.base/java.util.Arrays.copyOf(Arrays.java:3537)
        at java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:228)
        at java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:802)
        at java.base/java.lang.StringBuilder.append(StringBuilder.java:246)
        at net.thesimpleteam.picohttp.PicoHTTP.collectLines(PicoHTTP.java:184)
        at net.thesimpleteam.picohttp.PicoHTTP.lambda$listenForRequests$8(PicoHTTP.java:140)
        at net.thesimpleteam.picohttp.PicoHTTP$$Lambda$481/0x0000000800d3deb0.call(Unknown Source)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        ... 3 more
@Minemobs Minemobs self-assigned this Apr 16, 2023
@Minemobs Minemobs added the bug Something isn't working label Apr 16, 2023
@Minemobs Minemobs changed the title PicoHTTP#collectLines throws OutOfMemoryError when reading a large PicoHTTP#collectLines throws OutOfMemoryError when reading a file Apr 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant