Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B675718AA3 for ; Wed, 13 May 2015 09:11:06 +0000 (UTC) Received: (qmail 75150 invoked by uid 500); 13 May 2015 09:11:03 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 75047 invoked by uid 500); 13 May 2015 09:11:03 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 75035 invoked by uid 99); 13 May 2015 09:11:03 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 May 2015 09:11:03 +0000 Date: Wed, 13 May 2015 09:11:03 +0000 (UTC) From: "Kervin Pierre (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (IO-279) Tailer erroneously considers file as new MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/IO-279?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14541633#comment-14541633 ] Kervin Pierre edited comment on IO-279 at 5/13/15 9:10 AM: ----------------------------------------------------------- This issue is still present in 2.5-SNAPSHOT and I think found why, at least for my application. The problem is on some OSes 'File.lastmodified()' is cached until an event e.g. File.close(). This at least happens on Windows in some circumstances. I was monitoring a log4net file on a IIS application. This means that the file will grow in reported size as it remains open, but the 'lastmodified()' result will remain constant until that other application closes the file. Tailer does something very puzzling. It seek(0) this case... {code:title=Tailer.java|borderStyle=solid} } else if (newer) { /* * 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 position = readLines(reader); last = file.lastModified(); } {code} Shouldn't Tailer throw an exception worse case? But I would argue that seeing the lastmodified update but not seeing the size update isn't really an exception condition. The file could have been 'touched', lastmodified manually set other ways, etc. By the way, [~kgr] also proposed this in September 2013. [~spullara] also proposed this in February 2015. was (Author: kervin): This issue is still present in 2.5-SNAPSHOT and I think found why, at least for my application. The problem is on some OSes 'File.lastmodified()' is cached until an event e.g. File.close(). This at least happens on Windows in some circumstances. I was monitoring a log4net file on a IIS application. This means that the file will grow in reported size as it remains open, but the 'lastmodified()' result will remain constant until that other application closes the file. Tailer does something very puzzling. It seek(0) this case... {code:title=Bar.java|borderStyle=solid} } else if (newer) { /* * 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 position = readLines(reader); last = file.lastModified(); } {code} Shouldn't Tailer throw an exception worse case? But I would argue that seeing the lastmodified update but not seeing the size update isn't really an exception condition. The file could have been 'touched', lastmodified manually set other ways, etc. By the way, [~kgr] also proposed this in September 2013. [~spullara] also proposed this in February 2015. > Tailer erroneously considers file as new > ---------------------------------------- > > Key: IO-279 > URL: https://issues.apache.org/jira/browse/IO-279 > Project: Commons IO > Issue Type: Bug > Affects Versions: 2.0.1, 2.4 > Reporter: Sergio Bossa > Attachments: IO-279.patch, disable_resetting.patch, fix-tailer.patch, modify-test-fixed.patch, modify-test.patch > > > 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: > {code} > // 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); > } > {code} > 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? -- This message was sent by Atlassian JIRA (v6.3.4#6332)