kamijin-fanta opened a new issue, #13738:
URL: https://github.com/apache/iceberg/issues/13738
### Apache Iceberg version
1.7.1
### Query engine
None
### Please describe the bug 🐞
We are observing a persistent memory leak when using the Iceberg library in
long-running servers. Over time, heap usage steadily increases until we
investigate further:
1. **Heap dump analysis**
A heap dump revealed that `java.io.DeleteOnExitHook`’s static `files`
field (a `java.util.LinkedHashSet`) is retaining millions of entries such as
`/tmp/s3fileio-5245049253104386063.tmp`.
2. **Root cause**
In `S3OutputStream.java` , the code calls:
https://github.com/apache/iceberg/blob/apache-iceberg-1.9.2/aws/src/main/java/org/apache/iceberg/aws/s3/S3OutputStream.java#L220
Per the Javadoc, `File#deleteOnExit()` registers the file for JVM-exit
deletion and cannot be unregistered. Every call adds an entry to the global
`files` set, which never shrinks during normal operation:
https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/io/File.html#deleteOnExit()
3. **Why this is unnecessary**
Iceberg already has its own logic for cleaning up temporary files after
writes complete. In practice, those files are deleted as expected, making the
`deleteOnExit()` call redundant.
4. **Impact**
* Heap leaks grow without bound in servers that continuously write to S3
via Iceberg, eventually leading to OutOfMemoryErrors.
* Heap dumps show tens of millions of `String` objects hanging off
`DeleteOnExitHook`.
5. **Proposed solution**
Remove the `File#deleteOnExit()` call in `S3OutputStream.java`. All
temp-file cleanup should rely on the existing, explicit deletion logic in
Iceberg rather than the JVM shutdown hook.
<img width="1734" height="1029" alt="Image"
src="https://github.com/user-attachments/assets/163e654b-a896-4eb9-a39c-bc210f48c298"
/>
### Willingness to contribute
- [x] I can contribute a fix for this bug independently
- [x] I would be willing to contribute a fix for this bug with guidance from
the Iceberg community
- [ ] I cannot contribute a fix for this bug at this time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]