Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-279

Tailer erroneously considers file as new

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Reopened
    • Major
    • Resolution: Unresolved
    • 2.0.1, 2.4
    • None
    • None
    • None

    Description

      Tailer sometimes erroneously considers the tailed file as new, forcing a repositioning at the start of the file: I'm still unable to reproduce this in a test case, because it only happens to me with huge log files during Apache Tomcat startup.

      This is the piece of code causing the problem:

      // See if the file needs to be read again
      if (length > position) {
      
          // The file has more content than it did last time
          last = System.currentTimeMillis();
          position = readLines(reader);
      
      } else if (FileUtils.isFileNewer(file, last)) {
      
          /* This can happen if the file is truncated or overwritten
              * with the exact same length of information. In cases like
              * this, the file position needs to be reset
              */
          position = 0;
          reader.seek(position); // cannot be null here
      
          // Now we can read new lines
          last = System.currentTimeMillis();
          position = readLines(reader);
      }
      

      What probably happens is that the new file content is about to be written on disk, the date is already updated but content is still not flushed, so actual length is untouched and there you go.

      In other words, I think there should be some better method to verify the condition above, rather than relying only on dates: keeping and comparing the hash code of the latest line may be a solution, but may hurt performances ... other ideas?

      Attachments

        1. disable_resetting.patch
          3 kB
          Karol Grzegorczyk
        2. fix-tailer.patch
          1 kB
          Herman Meerlo
        3. IO-279.patch
          1 kB
          Niall Pemberton
        4. modify-test.patch
          2 kB
          Herman Meerlo
        5. modify-test-fixed.patch
          2 kB
          Herman Meerlo

        Activity

          People

            Unassigned Unassigned
            sbtourist Sergio Bossa
            Votes:
            5 Vote for this issue
            Watchers:
            24 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h
                1h