Skip to content

OutOfMemoryError on GHRepository.readZip due to lack of streaming  #1405

@blacelle

Description

@blacelle

Describe the bug
I encounter OutOfMemoryError over GHRepository.readZip while having reasonable free heap.

To Reproduce
Steps to reproduce the behavior:

  1. Consider a large Github repository (e.g. 50MB)
  2. Rely on GHRepository.readZip, while being a bit memory constrained (e.g. with Xmx128M)
  3. Encounter a OutOfMemoryError

Expected behavior
I would expect the whole InputStream not to be materialized in-memory by org.kohsuke.github.connector.GitHubConnectorResponse.ByteArrayResponse.bodyStream()

Additional context
A typical stack looks like:

Java heap space: java.lang.OutOfMemoryError
java.lang.OutOfMemoryError: Java heap space
	at org.apache.commons.io.output.AbstractByteArrayOutputStream.toByteArrayImpl(AbstractByteArrayOutputStream.java:366)
	at org.apache.commons.io.output.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:163)
	at org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:2241)
	at org.kohsuke.github.connector.GitHubConnectorResponse$ByteArrayResponse.bodyStream(GitHubConnectorResponse.java:187)
	at org.kohsuke.github.Requester.lambda$fetchStream$3(Requester.java:117)
	at org.kohsuke.github.Requester$$Lambda$568/0x00000008404da440.apply(Unknown Source)
	at org.kohsuke.github.GitHubClient.createResponse(GitHubClient.java:485)
	at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:387)
	at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:355)
	at org.kohsuke.github.Requester.fetchStream(Requester.java:117)
	at org.kohsuke.github.GHRepository.downloadArchive(GHRepository.java:3246)
	at org.kohsuke.github.GHRepository.readZip(GHRepository.java:3195)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions