Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource leak when using numbered split zip file #428

Closed
IcyBiscuit opened this issue May 17, 2022 · 2 comments
Closed

resource leak when using numbered split zip file #428

IcyBiscuit opened this issue May 17, 2022 · 2 comments
Assignees
Labels
bug Something isn't working resolved

Comments

@IcyBiscuit
Copy link

Hi,

We use this library to extract zip files on a Linux server (about 6000 files per day). After running a few days, the OS reports a too many open files error.

I use lsof -p PID to list open files and found about 40000 zip files are opened by one process.

After analysing the code, this issue may caused by an unclosed RandomAccessFile in net.lingala.zip4j.io.inputstream.NumberedSplitRandomAccessFile#randomAccessFile

here is the sample code to reproduce the issue:

@Test
public void numberSplitFd() throws IOException {
  String name = "/path/to/random-files/random.out copy %d.zip.001";
  for (int i = 1; i <= 10; i++) {
    // open the file, and close it using try-with-resource
    try (RandomAccessFile raf = new NumberedSplitRandomAccessFile(String.format(name, i),
        RandomAccessFileMode.READ.getValue())) {
    }
  }
  // add a breakpoint here and use lsof to check opened files
}

test files:
random-files.zip

lsof -p PID | grep 'zip.001'

java    8912 icybiscuit   11r   REG   1,4   1178   31937242 /Users/icybiscuit/Downloads/random-files/random.out copy 1.zip.001
java    8912 icybiscuit   12r   REG   1,4   1178   31937243 /Users/icybiscuit/Downloads/random-files/random.out copy 2.zip.001
java    8912 icybiscuit   13r   REG   1,4   1178   31937255 /Users/icybiscuit/Downloads/random-files/random.out copy 3.zip.001
java    8912 icybiscuit   14r   REG   1,4   1178   31937256 /Users/icybiscuit/Downloads/random-files/random.out copy 4.zip.001
java    8912 icybiscuit   15r   REG   1,4   1178   31937257 /Users/icybiscuit/Downloads/random-files/random.out copy 5.zip.001
java    8912 icybiscuit   16r   REG   1,4   1178   31937258 /Users/icybiscuit/Downloads/random-files/random.out copy 6.zip.001
java    8912 icybiscuit   17r   REG   1,4   1178   31937259 /Users/icybiscuit/Downloads/random-files/random.out copy 7.zip.001
java    8912 icybiscuit   18r   REG   1,4   1178   31937260 /Users/icybiscuit/Downloads/random-files/random.out copy 8.zip.001
java    8912 icybiscuit   19r   REG   1,4   1178   31937261 /Users/icybiscuit/Downloads/random-files/random.out copy 9.zip.001
java    8912 icybiscuit   20r   REG   1,4   1178   31937268 /Users/icybiscuit/Downloads/random-files/random.out copy 10.zip.001

add an override close method can resolve this issue

// net.lingala.zip4j.io.inputstream.NumberedSplitRandomAccessFile#close
@Override
public void close() throws IOException {
  if (null != randomAccessFile) {
    randomAccessFile.close();
  }
  super.close();
}
@srikanth-lingala
Copy link
Owner

Thanks for the detailed bug report. I appreciate that. I added the close method to NumberedSplitRandomAccessFile. Considering the urgency of this bug, I will make a (minor) release today after the build goes through.

@srikanth-lingala
Copy link
Owner

Fixed in v2.11.0 released today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved
Projects
None yet
Development

No branches or pull requests

2 participants