Skip to content

Fix copy large files#8409

Merged
eddumelendez merged 4 commits into
testcontainers:mainfrom
joschi:issue-4203
Jul 4, 2024
Merged

Fix copy large files#8409
eddumelendez merged 4 commits into
testcontainers:mainfrom
joschi:issue-4203

Conversation

@joschi

@joschi joschi commented Feb 29, 2024

Copy link
Copy Markdown
Contributor

This is an attempt to fix OutOfMemoryError (out of heap memory) when copying large files into a container via GenericContainer#withCopyFileToContainer().

The previous implementation relied on an in-memory array backing a ByteArrayInputStream which represents the tar archive sent to the Docker daemon which is limited by the available heap memory of the JVM at the moment of execution.

By using the local disk (temporary directory), we can copy files into the container which are larger than the available heap memory of the JVM. The caveat being that we are now limited by the available disk space in the temporary directory of the machine running Testcontainers.

Maybe it could be useful to perform this conditionally depending on the size of the transferables or configurable via runtime property.

What do you think?

Fixes #4203

@joschi joschi requested a review from a team February 29, 2024 21:31
@joschi joschi force-pushed the issue-4203 branch 2 times, most recently from 16693a6 to 3051f1f Compare March 5, 2024 21:29
@eddumelendez

Copy link
Copy Markdown
Member

Hi @joschi, thanks for the PR. What I had in mind for the issue is checking if copy file is supported to do an async operation and then implement it in docker-java and use it in Testcontainers.

This is an attempt to fix `OutOfMemoryError` (out of heap memory) when copying large files into a container via `GenericContainer#withCopyFileToContainer()`.

The previous implementation relied on an in-memory array backing a `ByteArrayInputStream` which represents the tar archive sent to the Docker daemon which is limited by the available heap memory of the JVM at the moment of execution.

By using the local disk (temporary directory), we can copy files into the container which are larger than the available heap memory of the JVM.
The caveat being that we are now limited by the available disk space in the temporary directory of the machine running Testcontainers.

Fixes testcontainers#4203
@eddumelendez eddumelendez added this to the next milestone Jul 4, 2024
@eddumelendez eddumelendez changed the title Use local disk for GenericContainer#withCopyFileToContainer() Fix copy large files Jul 4, 2024
@eddumelendez eddumelendez merged commit b4b1c20 into testcontainers:main Jul 4, 2024
@eddumelendez

Copy link
Copy Markdown
Member

Thanks for your contribution, @joschi ! PR has been updated to stream the files instead of use local disk.

@frankjkelly

Copy link
Copy Markdown

Fixing #7239 is amazing. Thank you so much!
Is there any thought or plan at this stage as to when we might get a release with the fix?
Thanks to all involved!

lizhou1111 pushed a commit to lizhou1111/testcontainers-java that referenced this pull request Jul 13, 2024
Fix `OutOfMemoryError` (out of heap memory) when copying large files into a container via `GenericContainer#withCopyFileToContainer()`.

Fixes testcontainers#4203

---------

Co-authored-by: Eddú Meléndez <eddu.melendez@gmail.com>
fokion pushed a commit to fokion/testcontainers-java that referenced this pull request Jan 18, 2025
Fix `OutOfMemoryError` (out of heap memory) when copying large files into a container via `GenericContainer#withCopyFileToContainer()`.

Fixes testcontainers#4203

---------

Co-authored-by: Eddú Meléndez <eddu.melendez@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GenericContainer#withCopyFileToContainer is not efficient memory-wise

3 participants