Created by: FuegoFro
Summary:
The current implementation calls ByteSource#openStream
, and none of the objects involved there close the stream in their finalize
method, so the process keeps the file descriptors for the temp files open forever. This a) prevents the actual content from being removed and b) can cause the process to hit its maximum number of file descriptors.
The change here is to use ByteSource#copyTo(OutputStream)
, which uses Guava's Closer
class to ensure that the stream will be closed, then calls the exact ByteStreams.copy
method that was being used before. Source for the newly used method can be found here.
Test Plan:
I ran the Buck daemon's HTTP server locally before the change and saw that cat /proc/sys/fs/file-nr
reported a monotonically increasing number of file descriptors held, and that lsof
reported the process holding onto a bunch of deleted files like buck-out/bin/outgoing_rulekey7730674455440792418.tmp
.
After this change, I ran the server locally and saw that the number of used file descriptors stayed stable over time and verified with lsof
that the process wasn't holding onto an tmp files.