Michael Han created ZOOKEEPER-2571:
--------------------------------------
Summary: Potential resource leak in QuorumPeer.writeLongToFile
Key: ZOOKEEPER-2571
URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2571
Project: ZooKeeper
Issue Type: Bug
Components: server
Affects Versions: 3.4.9
Reporter: Michael Han
Fix For: 3.4.10
In QuorumPeer.writeLongToFile we have:
{code}
try {
bw.write(Long.toString(value));
bw.flush();
out.flush();
} catch (IOException e) {
LOG.error("Failed to write new file " + file, e);
// worst case here the tmp file/resources(fd) are not cleaned up
// and the caller will be notified (IOException)
aborted = true;
out.abort();
throw e;
} finally {
if (!aborted) {
// if the close operation (rename) fails we'll get notified.
// worst case the tmp file may still exist
out.close();
}
}
{code}
So if any unchecked exception thrown during write (e.g. out of memory, you
never know), the output stream will not be closed. The fix is can be made by
having the flag set at the end of the try block instead of of in the catch
block, which only catch a specific type of exception (which is what
ZOOKEEPER-1835 did, thus the same issue does not exist in 3.5.x branch.).
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)