You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@zookeeper.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/03/28 15:08:00 UTC

[jira] [Updated] (ZOOKEEPER-2572) Potential resource leak in FileTxnLog.truncate

     [ https://issues.apache.org/jira/browse/ZOOKEEPER-2572?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

ASF GitHub Bot updated ZOOKEEPER-2572:
--------------------------------------
    Labels: pull-request-available  (was: )

> Potential resource leak in FileTxnLog.truncate
> ----------------------------------------------
>
>                 Key: ZOOKEEPER-2572
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2572
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: server
>    Affects Versions: 3.4.9, 3.5.2, 3.4.11
>            Reporter: Michael Han
>            Assignee: maoling
>            Priority: Major
>              Labels: pull-request-available
>
> In FileTxnLog.truncate, we have:
> {code}
> public boolean truncate(long zxid) throws IOException {
>         FileTxnIterator itr = null;
>         try {
>             itr = new FileTxnIterator(this.logDir, zxid);
>             PositionInputStream input = itr.inputStream;
>             if(input == null) {
>                 throw new IOException("No log files found to truncate! This could " +
>                         "happen if you still have snapshots from an old setup or " +
>                         "log files were deleted accidentally or dataLogDir was changed in zoo.cfg.");
>             }
>             long pos = input.getPosition();
>             // now, truncate at the current position
>             RandomAccessFile raf=new RandomAccessFile(itr.logFile,"rw");
>             raf.setLength(pos);
>             raf.close();
>             while(itr.goToNextLog()) {
>                 if (!itr.logFile.delete()) {
>                     LOG.warn("Unable to truncate {}", itr.logFile);
>                 }
>             }
>         } finally {
>             close(itr);
>         }
>         return true;
>     }
> {code}
> {{raf}} here can be potentially in a state of not closed after leaving the method, if there is an (IO) exception thrown from setLength.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)