Skip to content

Commit

Permalink
fixing crash on shutdown hook #1029 (#1032)
Browse files Browse the repository at this point in the history
* fixing the crash on shutdown introduced in #910 by changing the command that gets run on on deleteOnExit 
Files.delete() -> Files.deleteIfExists() 
this will prevent the jvm from crashing on shutdown if the temporary files get cleaned up before it closes

* This still leaves open the possibilty of crash on shutdown if the temporary file is unable to be removed for some other reason.  That's subtly different than the File version of deleteOnExit, but it may be useful to get these error messages in the unusual case of failing to delete a file that exists.

* fixes #1029
  • Loading branch information
lbergelson authored Nov 17, 2017
1 parent e2a03d6 commit eb364a4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/htsjdk/samtools/util/IOUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,16 @@ public static void deleteOnExit(final Path path) {
*
* @see #deleteOnExit(Path)
*/
protected static final class DeletePathThread extends Thread {
static final class DeletePathThread extends Thread {

private final Path path;

protected DeletePathThread(Path path) {this.path = path;}
DeletePathThread(Path path) {this.path = path;}

@Override
public void run() {
try {
Files.delete(path);
Files.deleteIfExists(path);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
Expand Down

3 comments on commit eb364a4

@KathieM
Copy link

@KathieM KathieM commented on eb364a4 Dec 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on a Mac and getting this error when I try to run "java -Xmx1024m -jar /Users/Shared/tools/picard/build/libs/picard.jar SortSam I=JLCN434.clean.bam O=JLCN434.picsort.bam SO=coordinate":
Exception in thread "Thread-30" htsjdk.samtools.util.RuntimeIOException: java.nio.file.NoSuchFileException: /var/folders/j6/jnlyr3zn265_9pn975ft55800000gp/T/kathiemihindukulasuriya/sortingcollection.4038297370218058636.tmp
at htsjdk.samtools.util.IOUtil$DeletePathThread.run(IOUtil.java:374)
Caused by: java.nio.file.NoSuchFileException: /var/folders/j6/jnlyr3zn265_9pn975ft55800000gp/T/kathiemihindukulasuriya/sortingcollection.4038297370218058636.tmp
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:244)
at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
at java.nio.file.Files.delete(Files.java:1126)
at htsjdk.samtools.util.IOUtil$DeletePathThread.run(IOUtil.java:372)

While I see the fix you posted, I cannot find the IOUtil.java file to implement the fix. Can you please give me some advice?

Thank you,
Kathie

@lbergelson
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @KathieM, the fix was made in htsjdk, but it seems like hasn't been incorporated into picard yet. Someone in that project will have to update it. I opened a pull request to update there just now , so it should happen soon broadinstitute/picard#1007

@KathieM
Copy link

@KathieM KathieM commented on eb364a4 Dec 2, 2017 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.