You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Michael Han (JIRA)" <ji...@apache.org> on 2016/09/09 05:34:20 UTC

[jira] [Created] (ZOOKEEPER-2571) Potential resource leak in QuorumPeer.writeLongToFile

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)