rbeckman-nextgen / test-mc6

0 stars 0 forks source link

ZIP archives not closed after importing and cannot be deleted until JVM dies #4353

Open rbeckman-nextgen opened 4 years ago

rbeckman-nextgen commented 4 years ago

The current version of NextGet Connect is affected by this issue: https://issues.apache.org/jira/browse/VFS-291.

Thus, if we import an archive previously created by the Data Pruner, the archive remains locked until the JMV dies.

Upgrading to Apache Commons VFS from 2.2 should do the trick (according to the release logs).

Imported Issue. Original Details: Jira Issue Key: MIRTH-4502 Reporter: sbraconnier Created: 2020-04-09T21:50:39.000-0700

rbeckman-nextgen commented 4 years ago

After some investigation, here's a patch that works, but not sure if it is the way you want to fix this. Better than nothing if you want to stick with the 2.1 version.

In the com.mirth.connect.util.MessageImporter class replace (around line 57):

` FileObject file = VfsUtils.getManager().resolveFile(VfsUtils.pathToUri(path));

switch (file.getType()) { case FOLDER: for (FileObject child : file.getChildren()) { if (recursive) { importVfsFileRecursive(child, messageWriter, result); } else if (child.getType() == FileType.FILE) { importVfsFile(child, messageWriter, result); } }

    break;

case FILE:
    importVfsFile(file, messageWriter, result);
    break;

} by FileObject file = null; try { file = VfsUtils.getManager().resolveFile(VfsUtils.pathToUri(path));

switch (file.getType()) {
    case FOLDER:
        for (FileObject child : file.getChildren()) {
            if (recursive) {
                importVfsFileRecursive(child, messageWriter, result);
            } else if (child.getType() == FileType.FILE) {
                importVfsFile(child, messageWriter, result);
            }
        }

        break;

    case FILE:
        importVfsFile(file, messageWriter, result);
        break;
}

} finally { if (file != null) { try { file.close(); } finally { // Fix: // https://github.com/nextgenhealthcare/connect/issues/21 // Which is caused by: // https://issues.apache.org/jira/browse/VFS-291 // And have been fixed by this commit: // https://github.com/apache/commons-vfs/commit/4c3b552c6d3e8f08e0cd41577292103a5c549142 if (file instanceof ZipFileObject) { ZipFileSystem afs = (ZipFileSystem) file.getFileSystem(); if (!afs.isOpen()) { afs.close(); } } } } } `

Imported Comment. Original Details: Author: sbraconnier Created: 2020-04-09T21:52:40.000-0700

rbeckman-nextgen commented 4 years ago

This would also work, but it will also clear the manager cache (which should not be a problem for import).

` FileObject file = null; FileSystemManager manager = null; try { manager = VfsUtils.getManager(); file = manager.resolveFile(VfsUtils.pathToUri(path));

switch (file.getType()) {
    case FOLDER:
        for (FileObject child : file.getChildren()) {
            if (recursive) {
                importVfsFileRecursive(child, messageWriter, result);
            } else if (child.getType() == FileType.FILE) {
                importVfsFile(child, messageWriter, result);
            }
        }

        break;

    case FILE:
        importVfsFile(file, messageWriter, result);
        break;
}

} finally { if (file != null) { try { file.close(); } finally { // This fix the bug AND will clear the cache. manager.closeFileSystem(file.getFileSystem()); } } } `

Imported Comment. Original Details: Author: sbraconnier Created: 2020-04-18T04:39:49.000-0700