Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Endless loop when detecting filesystem timestamps resolution
  • From: "Sohn, Matthias" <matthias.sohn@xxxxxxx>
  • Date: Wed, 17 Jul 2019 15:12:49 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=sap.com; dmarc=pass action=none header.from=sap.com; dkim=pass header.d=sap.com;arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DLUVf3vKDORprc/Rt8EB72vrZO094U49tRhohDNEZRA=; b=Nj4gZgtKkoHiDln6fRnj0HWPfmWU6o0+3xyTqJPve97GLGhRWMqMGgVPmivBrcRLwubrWIYhuV1S2Ee+LhLG5C3Ra6IhKn3o3tYVPYVoj+Aniyqpk24pcvyuX+mbS0pGD9GwaUViSozcr6fPx8PjQ/EEBUBJJKw/TGNyxt41QZZtOjUg/SeKWrtiAX8/DdAFS/zry5DNH4woovSPlhOxIRA0vgipapUWreuE552+DF+m/ySbevjzSbpWpYeuAvZX4BAx3u/NG5XYL68zLOl90YahMaf971ONVn+Wo2cS5mxIwPRQG/w+XnlL34dD4SKTf/pMASv+CtGgKDp+p0AAuA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iQk/71pjPLg76Ejup3KNZC9EF9B7u/qDXCSna3NuLHLJoVZLrP8wvYjpAIh4Kzakzvh52y9IetNVuvH81E5EELhagXfYcGAHa0BiJyaEvDUk4oorfTMbVE71TcmUMaxMejk8SUEe0xr2tBUIoDmgnTHPsJ+UdhzrOHsYT0MHdFJvYl+GxAZH6dDG6T/hB+gt5I//d95u5I8zBjSVwsWP6VeJjb65ZyROmpDXKD2OiEBx7a1eordtA7e15/F69XKB5wkmshQeArkYBp+yDRMCaLarqbS4HXSnfLOKYdOCR0nDXwuR+DH1rWSAWqmtkI4CgwqLqlhdxlFrjpA/G4p7fQ==
  • Delivered-to: jgit-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/jgit-dev>
  • List-help: <mailto:jgit-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/jgit-dev>, <mailto:jgit-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/jgit-dev>, <mailto:jgit-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AQHVPLIYWVXsbX7XlU285cvy+HFvhA==
  • Thread-topic: [jgit-dev] Endless loop when detecting filesystem timestamps resolution
  • User-agent: Microsoft-MacOutlook/10.1a.0.190609

This is bug 548598 [1], a patch for this bug was merged on the stable-5.1 branch recently.
I am working on a series of patches [2], as soon as this is merged service releases will be created from 5.1.9 up to 5.4.1

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=548598
[2] https://git.eclipse.org/r/#/c/146085/

-Matthias

On 17.07.19, 16:33, "jgit-dev-bounces@xxxxxxxxxxx on behalf of Dmitry Pavlenko" <jgit-dev-bounces@xxxxxxxxxxx on behalf of pavlenko@xxxxxxxxxxxxx> wrote:

    Hello!
    
    We're using JGit library internally and for one of our clients it entered into an endless loop.
    
    The stack trace obtained by 'jstack' is
    
       java.lang.Thread.State: TIMED_WAITING (sleeping)
            at java.lang.Thread.sleep(Native Method)
            at java.lang.Thread.sleep(Thread.java:340)
            at java.util.concurrent.TimeUnit.sleep(TimeUnit.java:386)
            at org.eclipse.jgit.util.FS$FileStoreAttributeCache.<init>(FS.java:242)
            at org.eclipse.jgit.util.FS$FileStoreAttributeCache.getFsTimestampResolution(FS.java:213)
            at org.eclipse.jgit.util.FS.getFsTimerResolution(FS.java:323)
            at org.eclipse.jgit.internal.storage.file.FileSnapshot.<init>(FileSnapshot.java:186)
            at org.eclipse.jgit.internal.storage.file.FileSnapshot.save(FileSnapshot.java:122)
            at org.eclipse.jgit.storage.file.FileBasedConfig.load(FileBasedConfig.java:159)
            at org.eclipse.jgit.internal.storage.file.FileRepository.loadUserConfig(FileRepository.java:261)
            at org.eclipse.jgit.internal.storage.file.FileRepository.<init>(FileRepository.java:197)
            at org.eclipse.jgit.lib.RepositoryCache$FileKey.getGitRepository(RepositoryCache.java:519)
            at org.eclipse.jgit.lib.RepositoryCache$FileKey.isGitRepository(RepositoryCache.java:500)
    
    So the problem happens in the following code:
    
    				FileTime startTime = Files.getLastModifiedTime(probe);
    				FileTime actTime = startTime;
    				long sleepTime = 512;
    				while (actTime.compareTo(startTime) <= 0) {
    					TimeUnit.NANOSECONDS.sleep(sleepTime);
    					FileUtils.touch(probe);
    					actTime = Files.getLastModifiedTime(probe);
    					// limit sleep time to max. 100ms
    					if (sleepTime < 100_000_000L) {
    						sleepTime = sleepTime * 2;
    					}
    				}
    
    JGit creates a file named .probe-<UUID> and the 'touches' it until its 'mtime' is greater than the creation time.
    And for the user it seems that FileUtils#touch is no-op and hence the cycle never ends.
    
    The user also tried different filesystems and the problem happens on all filesystems. So it doesn't seem to be
    a problem of a particular filesystem. The mounting options also don't have anything special.
    
    Moreover, when the user 'touches' the .probe-<UUID> file with 'touch' command line,
    the cycle finishes and the program continues. So I would conclude that the problem is in implementation
    of FileUtils#touch (JVM is OpenJDK 25.212-b03):
    
    	public static void touch(Path f) throws IOException {
    		try (OutputStream fos = Files.newOutputStream(f)) {
    			// touch the file
    		}
    	}
    
    Also one of my colleagues recalled that he had similar problem with SVNKit: 'mtime' wasn't updated with just
    opening+closing the file, but writing something was necessary; and the problem was really rare.
    
    The user experienced JGit problem has Ubuntu, we tried to reproduce the problem on Ubuntu and the same filesystems and
    we couldn't. I cannot reproduce the problem on my machine as well.
    
    There's also an interesting longread regarding 'mtime':
       https://apenwarr.ca/log/20181113 
    
    I'll cite a piece:
     * Is mtime always nonzero?
      No. Various cheaply-written virtual filesystems, like many fuse-based ones, don't bother setting mtime.
    
    So I would suggest to 
      - limit the number of iterations for this cycle to prevent the endless loop;
      - implement 'touch' in a different way, e.g. by writing something into the file (this doesn't solves the problem of hypothetical
            "cheaply-written virtual filesystems" though).
    
    Here's the corresponding issue on our tracker: https://issues.tmatesoft.com/issue/SGT-1308
    -- 
    Dmitry Pavlenko,
    TMate Software,
    http://subgit.com/ - git-svn bridge
    
    
    
    _______________________________________________
    jgit-dev mailing list
    jgit-dev@xxxxxxxxxxx
    To change your delivery options, retrieve your password, or unsubscribe from this list, visit
    https://www.eclipse.org/mailman/listinfo/jgit-dev
    


Back to the top