Skip to content

Commit

Permalink
[FIXED JENKINS-20345] file descriptor leak in zip file download
Browse files Browse the repository at this point in the history
When downloading a zip file with all of the artifacts, file descriptors
would be opened and never closed. This resulted in many leaked file
descriptors which would only be cleaned up the next time the garbage
collector was run.

For directories with a large number of files, the zip file would be
corrupted because an exception was thrown during the process of creating
the zip file when the process ran out of file descriptors. Jenkins was
then left in a very brittle state as random threads wouldn't be able to
open files or sockets anymore until the garbage collector was run.
  • Loading branch information
jsternberg committed Jan 14, 2014
1 parent 4ace130 commit f0bbc66
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/main/java/hudson/model/DirectoryBrowserSupport.java
Expand Up @@ -26,6 +26,7 @@
import hudson.FilePath;
import hudson.Util;
import jenkins.model.Jenkins;
import org.apache.commons.io.IOUtils;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.HttpResponse;
Expand Down Expand Up @@ -351,7 +352,12 @@ private static void zip(OutputStream outputStream, VirtualFile dir, String glob)
VirtualFile f = dir.child(n);
e.setTime(f.lastModified());
zos.putNextEntry(e);
Util.copyStream(f.open(), zos);
InputStream in = f.open();
try {
Util.copyStream(in, zos);
} finally {
IOUtils.closeQuietly(in);
}
zos.closeEntry();
}
zos.close();
Expand Down

0 comments on commit f0bbc66

Please sign in to comment.