Commit 41e6b2ad authored by Andy Wilkinson's avatar Andy Wilkinson

Improve diagnostics when temporary heap dump file can't be deleted

parent e7a3b3c4
......@@ -24,12 +24,16 @@ import java.lang.management.PlatformManagedObject;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.endpoint.Endpoint;
import org.springframework.boot.endpoint.EndpointType;
......@@ -184,6 +188,8 @@ public class HeapDumpWebEndpoint {
private static final class TemporaryFileSystemResource extends FileSystemResource {
private final Log logger = LogFactory.getLog(getClass());
private TemporaryFileSystemResource(File file) {
super(file);
}
......@@ -204,7 +210,7 @@ public class HeapDumpWebEndpoint {
readableChannel.close();
}
finally {
getFile().delete();
deleteFile();
}
}
......@@ -252,7 +258,7 @@ public class HeapDumpWebEndpoint {
delegate.close();
}
finally {
getFile().delete();
deleteFile();
}
}
......@@ -274,6 +280,17 @@ public class HeapDumpWebEndpoint {
};
}
private void deleteFile() {
try {
Files.delete(getFile().toPath());
}
catch (IOException ex) {
TemporaryFileSystemResource.this.logger.warn(
"Failed to delete temporary heap dump file '" + getFile() + "'",
ex);
}
}
@Override
public boolean isFile() {
// Prevent zero-copy so we can delete the file on close
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment