[
https://issues.apache.org/jira/browse/HDFS-16031?focusedWorklogId=601041&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-601041
]
ASF GitHub Bot logged work on HDFS-16031:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 24/May/21 06:55
Start Date: 24/May/21 06:55
Worklog Time Spent: 10m
Work Description: aajisaka commented on a change in pull request #3027:
URL: https://github.com/apache/hadoop/pull/3027#discussion_r637728863
##########
File path:
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/aliasmap/InMemoryAliasMap.java
##########
@@ -320,21 +320,18 @@ static File createSnapshot(InMemoryAliasMap aliasMap)
throws IOException {
private static File getCompressedAliasMap(File aliasMapDir)
throws IOException {
File outCompressedFile = new File(aliasMapDir.getParent(), TAR_NAME);
- BufferedOutputStream bOut = null;
- GzipCompressorOutputStream gzOut = null;
- TarArchiveOutputStream tOut = null;
- try {
- bOut = new BufferedOutputStream(
- Files.newOutputStream(outCompressedFile.toPath()));
- gzOut = new GzipCompressorOutputStream(bOut);
- tOut = new TarArchiveOutputStream(gzOut);
+
+ try (BufferedOutputStream bOut = new BufferedOutputStream(
+ Files.newOutputStream(outCompressedFile.toPath()));
+ GzipCompressorOutputStream gzOut = new
GzipCompressorOutputStream(bOut);
+ TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut)){
+
addFileToTarGzRecursively(tOut, aliasMapDir, "", new Configuration());
- } finally {
if (tOut != null) {
tOut.finish();
}
Review comment:
Thanks for the update.
- Before: `tOut.finish()` is called if addFileToTarGzRecursively throws an
exception.
- Your patch: `tOut.finish()` is not called if addFileToTarGzRecursively
throws an exception.
I think we need to have an extra try-catch clause:
```java:
try {
addFileToTarGzRecursively(tOut, aliasMapDir, "", new
Configuration());
} finally {
tOut.finish();
}
```
tOut cannot be null in the try-with-resources clause so that we can remove
the null check.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 601041)
Time Spent: 50m (was: 40m)
> Possible Resource Leak in
> org.apache.hadoop.hdfs.server.aliasmap#InMemoryAliasMap
> ---------------------------------------------------------------------------------
>
> Key: HDFS-16031
> URL: https://issues.apache.org/jira/browse/HDFS-16031
> Project: Hadoop HDFS
> Issue Type: Bug
> Reporter: Narges Shadab
> Priority: Major
> Labels: pull-request-available
> Time Spent: 50m
> Remaining Estimate: 0h
>
> We notice a possible resource leak in
> [getCompressedAliasMap|https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/aliasmap/InMemoryAliasMap.java#L320].
> If {{finish()}} at line 334 throws an IOException, then {{tOut, gzOut}} and
> {{bOut}} remain open since the exception isn't caught locally, and there is
> no way for any caller to close them.
> I've submitted a pull request to fix it.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]