| Summary: | race condition affecting org.eclipse.jgit.storage.file.ObjectDirectoryInserter.insert(...) when called concurrently from multiple threads | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Technology] JGit | Reporter: | Quentin Burley <quentinburley> | ||||
| Component: | JGit | Assignee: | Project Inbox <jgit.core-inbox> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | quentinburley | ||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | All | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
|
Description
Quentin Burley
Created attachment 225082 [details]
[PATCH] call FileUtils.mkdir(dst.getParentFile(), true); i.e. with skipExisting=true. instead of FileUtils.mkdir(dst.getParentFile());
call FileUtils.mkdir(dst.getParentFile(), true);
i.e. with skipExisting=true.
instead of FileUtils.mkdir(dst.getParentFile());
In order to resolve a race condition that occurs when different threads attempt to create the same directory concurrently.
Such a can condition occur when invoking org.eclipse.jgit.storage.file.ObjectDirectoryInserter.insert(...) concurrently from multiple threads.
fixed by commit (author: rtyley): https://github.com/eclipse/jgit/commit/5dcc8693d7d1ab81e3d6e6583a3918a3b6003bad Fix concurrent creation of fan-out object directories If multiple threads attempted to insert loose objects into the same new fan-out directory, the creation of that directory was subject to a race condition that could lead to an unnecessary IOException being thrown - because an inserter could not 'create' a directory that had just been generated by a different thread. All we require is that the directory does indeed *exist*, so not being able to _create_ it is not actually a fatal problem. Setting 'skipExisting' to 'true' on the call to mkdir() fixes the issue. I found this issue as a real world occurrence while working on The BFG Repo Cleaner (https://github.com/rtyley/bfg-repo-cleaner), a tool which concurrently performs a lot of object creation. In order to demonstrate the problem here I've added a small test case which reliably reproduces the issue on the few different hardware systems I've tried. The error thrown when the race-condition arises is this: java.io.IOException: Creating directory /home/roberto/repo.git/objects/e6 failed at org.eclipse.jgit.util.FileUtils.mkdir(FileUtils.java:182) at org.eclipse.jgit.storage.file.ObjectDirectory.insertUnpackedObject(ObjectDirectory.java:590) at org.eclipse.jgit.storage.file.ObjectDirectoryInserter.insertOneObject(ObjectDirectoryInserter.java:113) at org.eclipse.jgit.storage.file.ObjectDirectoryInserter.insert(ObjectDirectoryInserter.java:91) at org.eclipse.jgit.lib.ObjectInserter.insert(ObjectInserter.java:329) Change-Id: I88eac49bc600c56ba9ad290e6133d8a7113125ab master v3.0.0.201305080800-m7 … v2.3.0.201302130906 fixed by commit (author: rtyley): https://github.com/eclipse/jgit/commit/5dcc8693d7d1ab81e3d6e6583a3918a3b6003bad |