[ 
https://issues.apache.org/jira/browse/IO-398?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13765529#comment-13765529
 ] 

Sebb commented on IO-398:
-------------------------

Thanks!

I've been trying the unit test, and on Windows it sometimes fails to delete the 
file.
I assume that is because the tailer must have it open at the time.
The test can be updated to retry the delete.

This reveals an additional issue if the "reopen" option is true (as is required 
for Windows).
If the logger deletes/renames the file, the Tailer can fail with 
FileNotFoundException if the logger has not replaced the file by the time the 
wait has expired. This needs to be fixed before the IO-398 test case is usable 
on Windows.
                
> listener.fileRotated() will be invoked more than one time in a real rotate 
> activity
> -----------------------------------------------------------------------------------
>
>                 Key: IO-398
>                 URL: https://issues.apache.org/jira/browse/IO-398
>             Project: Commons IO
>          Issue Type: Bug
>    Affects Versions: 2.4
>            Reporter: Lantao Jin
>         Attachments: IO-398.patch, IO398_with_ut.patch
>
>
>        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:
> {noformat} 
> 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;
> {noformat}
>       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.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to