Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, NVIDIA CORPORATION.
* Copyright (c) 2025-2026, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -355,16 +355,22 @@ object AsyncProfilerOnExecutor extends Logging {
// Compress the temp file first
val compressedTempPath = Files.createTempFile("compressed-jfr", ".gz")
if (compressJfrFile(tempFilePath, compressedTempPath)) {
fs.copyFromLocalFile(new Path(compressedTempPath.toString), outPath)
withResource(fs.create(outPath, false)) { out =>
Files.copy(compressedTempPath, out)
}
compressedTempPath.toFile.delete() // delete compressed temp file
Comment on lines 357 to 361
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Compressed temp file not deleted on exception

If Files.copy(compressedTempPath, out) throws, withResource correctly closes out, but the compressedTempPath.toFile.delete() on line 361 is skipped, leaking the compressed temp file. The same exception also skips the tempFilePath.toFile.delete() at line 374. A try/finally (or a second withResource-like guard) around compressedTempPath would ensure cleanup on both normal and exceptional paths.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@greptile-apps this is an existing issue, isn't it? Even before this change, compressedTempPath will be never deleted if fs.copyFromLocalFile throws.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're right, that's a pre-existing issue that this PR didn't introduce. My comment was unfair to flag as part of this review since the change doesn't make the cleanup situation any worse than before. Thanks for the correction.

Tip: You can give me more context with [.greptile/rules.md](https://www.greptile.com/docs/code-review/custom-standards) so I get this right next time.

} else {
// If compression fails, copy the original file
log.warn("JFR compression failed, copying uncompressed file")
fs.copyFromLocalFile(new Path(tempFilePath.toString),
new Path(asyncProfilerPrefix.get, baseFileName))
withResource(
fs.create(new Path(asyncProfilerPrefix.get, baseFileName), false)) { out =>
Files.copy(tempFilePath, out)
}
}
} else {
fs.copyFromLocalFile(new Path(tempFilePath.toString), outPath)
withResource(fs.create(outPath, false)) { out =>
Files.copy(tempFilePath, out)
}
}
tempFilePath.toFile.delete() // delete the original temp file after moving
} else {
Expand Down