Randall Theobald created IO-530:
-----------------------------------

             Summary: Tailer pegs CPU if file disappears and doesn't come back
                 Key: IO-530
                 URL: https://issues.apache.org/jira/browse/IO-530
             Project: Commons IO
          Issue Type: Bug
    Affects Versions: 2.5
            Reporter: Randall Theobald
            Priority: Critical


I ran into a situation where a bug in my log rotation leads to the tailed file 
being renamed, but the original file name does not re-appear (new log entries 
still go to the renamed log file). This uncovered a bug in the Tailer class. In 
this case, tailer enters a tight loop trying to re-open the file:
{code}
while (getRun()) {
                final boolean newer = FileUtils.isFileNewer(file, last); // 
IO-279, must be done first
                // Check the file length to see if it was rotated
                final long length = file.length();
                if (length < position) {
                    // File was rotated
                    listener.fileRotated();
                    // Reopen the reader after rotation ensuring that the old 
file is closed iff we re-open it
                    // successfully
                    try (RandomAccessFile save = reader) {
                        reader = new RandomAccessFile(file, RAF_MODE);
                        // At this point, we're sure that the old file is 
rotated
                        // Finish scanning the old file and then we'll start 
with the new one
                        try {
                            readLines(save);
                        }  catch (IOException ioe) {
                            listener.handle(ioe);
                        }
                        position = 0;
                    } catch (final FileNotFoundException e) {
                        // in this case we continue to use the previous reader 
and position values
                        listener.fileNotFound();
                    }
                    continue;
{code}
Since a non-existent file returns a length of zero, we keep entering this top 
loop, trying to open the missing file, getting a FileNotFoundException and 
starting over.

There should be some delay here.




--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to