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

listener.fileRotated() will be invoked more than one time in a real rotate activity

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.4
    • None
    • None
    • None

    Description

      When Tailer considers file rotation is occurred, listener.fileRotated() will be execute, and file will re-open by "reader = new RandomAccessFile(file, RAF_MODE);". However, the new file may not be created yet, FileNotFoundException would be caught and while loop would be executed again and again until the new file is actually created, which cause listener.fileRotated() triggered repeatedly.
      This is the piece of code causing the problem:

       
      while (getRun()) {
          final boolean newer = 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
              try {
                  // Ensure that the old file is closed iff we re-open it successfully
                  final RandomAccessFile save = reader;
                  reader = new RandomAccessFile(file, RAF_MODE);
                  /* some code */
              } catch (final FileNotFoundException e) {
                  // in this case we continue to use the previous reader and position values
                  listener.fileNotFound();
              }
              continue;
      

      While condition checkes can be deployed in listener.fileRotated() to correct the sematic of fileRotate, it is better to prevent multiple invocation of listener.fileRotated() on this issue.

      Attachments

        1. IO-398.patch
          3 kB
          Lantao Jin
        2. IO398_with_ut.patch
          4 kB
          Lantao Jin

        Issue Links

          Activity

            People

              Unassigned Unassigned
              cltlfcjin Lantao Jin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: