commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Randall Theobald (JIRA)" <>
Subject [jira] [Created] (IO-530) Tailer pegs CPU if file disappears and doesn't come back
Date Fri, 17 Mar 2017 17:07:41 GMT
Randall Theobald created IO-530:

             Summary: Tailer pegs CPU if file disappears and doesn't come back
                 Key: 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:
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
                    // 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
                        try {
                        }  catch (IOException ioe) {
                        position = 0;
                    } catch (final FileNotFoundException e) {
                        // in this case we continue to use the previous reader and position
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

View raw message