Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 366684

Summary: "Failed to add resource to index" error for a subsequent "Add to Index"
Product: [Technology] EGit Reporter: Tomasz Zarna <tomasz.zarna>
Component: CoreAssignee: Jens Baumgart <jens.baumgart>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: dariusz.luksza, jens.baumgart, matthias.sohn, robin
Version: 1.2   
Target Milestone: 1.3   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Tomasz Zarna CLA 2011-12-14 07:01:31 EST
I20111209-1447 + EGit	1.2.0.201112111816

What steps will reproduce the problem?
1. Team > Add on first project from a repo
2. Quickly repeat the same action on a different project in the same repo
3. Inspect the Error Log

-- Error Details --
Date: Wed Dec 14 12:57:24 CET 2011
Message: Failed to add resource to index
Severity: Error
Product: Eclipse SDK 3.8.0.v201112091447 (org.eclipse.sdk.ide)
Plugin: org.eclipse.egit.core
Session Data:
eclipse.buildId=I20111209-1447
java.fullversion=JRE 1.6.0 IBM J9 2.4 Windows XP x86-32 jvmwi3260sr7-20091214_49398 (JIT enabled, AOT enabled)
J9VM - 20091214_049398
JIT  - r9_20091123_13891
GC   - 20091111_AA
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=pl_PL
Command-line arguments:  -os win32 -ws win32 -arch x86

Exception Stack Trace:
org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of add command
	at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:199)
	at org.eclipse.egit.core.op.AddToIndexOperation.execute(AddToIndexOperation.java:78)
	at org.eclipse.egit.ui.internal.actions.AddToIndexActionHandler$1.run(AddToIndexActionHandler.java:56)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: java.io.IOException: Cannot lock D:\workspace\eclipse\egit\egit\.git\index
	at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:193)
	at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:239)
	at org.eclipse.jgit.lib.Repository.lockDirCache(Repository.java:873)
	at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:136)
	... 3 more
	
org.eclipse.core.runtime.CoreException: Failed to add resource to index
	at org.eclipse.egit.core.op.AddToIndexOperation.execute(AddToIndexOperation.java:81)
	at org.eclipse.egit.ui.internal.actions.AddToIndexActionHandler$1.run(AddToIndexActionHandler.java:56)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of add command
	at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:199)
	at org.eclipse.egit.core.op.AddToIndexOperation.execute(AddToIndexOperation.java:78)
	... 2 more
Caused by: java.io.IOException: Cannot lock D:\workspace\eclipse\egit\egit\.git\index
	at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:193)
	at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:239)
	at org.eclipse.jgit.lib.Repository.lockDirCache(Repository.java:873)
	at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:136)
	... 3 more
Comment 1 Tomasz Zarna CLA 2011-12-14 07:02:26 EST
Worked fine when repeated after a while.
Comment 2 Tomasz Zarna CLA 2011-12-14 07:07:16 EST
Just now I noticed that "git status" shows me a lot of changes (staged) for files I haven't touched. So far these are EOL diffs, but still it's a mess. Bumping severity.
Comment 3 Jens Baumgart CLA 2011-12-19 07:43:25 EST
Proposed a fix for missing unlock calls in finally blocks:

http://egit.eclipse.org/r/4859

But I assume this is not the root cause of the problem.
Currently the AddToIndexOperation provides the input resources as scheduling rule. This is wrong because this suggests that two Add To Index Jobs could run in parallel if the resources belong to the same Git repository.
A better solution would be using a scheduling rule with all projects of the related Git repository.

The scheduling rules of other EGit operations need to be checked, too.
Comment 4 Matthias Sohn CLA 2011-12-19 08:44:18 EST
merged http://egit.eclipse.org/r/4859 as 6b68574c5e3585620736b1a70ce92984c9f18cab
Comment 5 Jens Baumgart CLA 2011-12-22 11:20:36 EST
Fix proposed: http://egit.eclipse.org/r/4871

The fix avoids two add Jobs running in parallel.
Comment 6 Jens Baumgart CLA 2011-12-22 11:22:12 EST
(In reply to comment #5)
> Fix proposed: http://egit.eclipse.org/r/4871
> 
> The fix avoids two add Jobs running in parallel.

The fix avoids two add Jobs running in parallel if the Jobs are related to resources belonging to the same Git repository.
Comment 7 Dariusz Luksza CLA 2012-01-14 09:28:03 EST
merged http://egit.eclipse.org/r/4871 as 99354e31eee9a6e73c394fc4a6be90b32956dec2
Comment 8 Tomasz Zarna CLA 2012-01-26 08:49:53 EST
Marking as fixed, see comment 7. I haven't verified the fix though.