I am trying to use NGit library in my application (C#, MS.NET 4.0). As we are on MS platform I have rebuilt the NGit for .NET Framework 4.0 under VS 2010. Most things are good and all the functionality works well but the application hangs on its shutdown. VS Debugger shows that some thread from Sharpen lib stays infinitely in the waiting state and nobody signals it to shutdown. That happens when I use any of the instance methods of NGit.Api.Git class (for static methods things seem to be OK). Did anybody experience such issues? Any suggestions?
Example of code using Git class:
Git myrepo = Git.Init().SetDirectory(@"C:\myrepo.git").SetBare(true).Call();
FetchResult fetchResult = myrepo.Fetch()
.SetProgressMonitor(new TextProgressMonitor())
.SetRemote(@"C:\projects\initialrepo")
.SetRefSpecs(new RefSpec("refs/heads/master:refs/heads/master"))
.Call();
//
// Some other work...
//
myrepo.GetRepository().Close();
And here is the place where the thread hangs:
Class Sharpen.ThreadExecutor, line 9 below (St.Monitor.Wait (pendingTasks)):
public void RunPoolThread ()
{
while (!IsTerminated ()) {
try {
Runnable r = null;
lock (pendingTasks) {
freeThreads++;
while (!IsTerminated () && pendingTasks.Count == 0)
ST.Monitor.Wait (pendingTasks);
if (IsTerminated ())
break;
r = pendingTasks.Dequeue ();
}
if (r != null)
r.Run ();
}
catch (ST.ThreadAbortException) {
ST.Thread.ResetAbort ();
}
catch {
}
}
}
I did get the library and ran the tests. I found some of the relevant tests to fail intermittently. I don’t know if the test cases are wrong or whether there is an actual problem.
I reported the issue here: https://github.com/slluis/ngit/issues/8
I’ll have a look at the particular code you added, I’ve just seen it
I tested the following code on
The problem appears to be that the static
BatchingProgressMonitor(which is also constructed when you do not register theTextProgressMonitor) is never ‘destructed’, meaning that the alarmQueue with it’s associated thread-pool is neverShutdown.If you add the following public method to the class
BatchingProgressMonitor:you can have a ‘workaround’ by calling
BatchingProgressMonitor.ShutdownNow()before exiting your application. This WorkedForMeTM. The sample code shows how to do that when you remove the#if/#endif..
I’ll report this at the issue tracker too. Edit Done: here
Cheers,
Seth