testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

Use local disk for GenericContainer#withCopyFileToContainer()

Open joschi opened this issue 1 year ago • 1 comments

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 avatar Feb 29 '24 21:02 joschi

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.

eddumelendez avatar Mar 13 '24 19:03 eddumelendez

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

eddumelendez avatar Jul 04 '24 22:07 eddumelendez

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!

frankjkelly avatar Jul 05 '24 11:07 frankjkelly