Cannot run NAnt tasks in parallel due to JetBrains.BuildServer.NAntLoggers.dll not being thread-safe
I've created a custom NAnt task that launches a given list of targets in parallel on separate threads then waits for them all to complete.
This runs fine when running via command line, but when running via TeamCity it seems to expose a place where the JetBrains.BuildServer.NAntLoggers.dll and subsequently the NAnt.Core
Sometimes it passes, mostly it fails.
Here is the stacktrace:
System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext() at NAnt.Core.TaskBuilderCollection.get_Item(String taskName) at
JetBrains.BuildServer.NAntLoggers.TasksPatcher.PatchTask(String name, Type t) in c:\Agent\work\c283f2bd6aafd2d9\src\NAntLoggers\src\TasksPatcher.cs:line 52 at
JetBrains.BuildServer.NAntLoggers.TasksPatcher.PatchTasks() in c:\Agent\work\c283f2bd6aafd2d9\src\NAntLoggers\src\TasksPatcher.cs:line 33 at
JetBrains.BuildServer.NAntLoggers.NAntListenerImpl.TargetStarted(BuildEventArgs e) in c:\Agent\work\c283f2bd6aafd2d9\src\NAntLoggers\src\NAntListenerImpl.cs:line 82 at
JetBrains.BuildServer.NAntLoggers.NAntListener2.TargetStarted(Object sender, BuildEventArgs e) in c:\Agent\work\c283f2bd6aafd2d9\src\NAntLoggers\src\NAntListener2.cs:line 62 at
JetBrains.BuildServer.NAntLoggers.NAntListener.TargetStarted(Object sender, BuildEventArgs e) in c:\Agent\work\c283f2bd6aafd2d9\src\NAntLoggers\src\NAntListener.cs:line 33 at
NAnt.Core.BuildEventHandler.Invoke(Object sender, BuildEventArgs e) at NAnt.Core.Project.OnTargetStarted(Object sender, BuildEventArgs e) at NAnt.Core.Target.Execute() at
NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies) at
NAnt.Core.Tasks.CallTask.ExecuteTask() at NAnt.Core.Task.Execute() at
CustomNAntTasks.CallAsyncAndWait.<>c__DisplayClassa.<ExecuteTask>b__3(String targetName)
Any ideas how I could work around this thread-safe problem? Or any chances of making the Jetbrains code thread-safe?
Please sign in to leave a comment.
Hello,
There is no support of parallel tasks execution in NAnt, that is why there is no support of it from TeamCity side.
This seems you start serval projects at a time and this our listener is called more than once.
Running several project at a time could also affect NAnt-to-TeamCity loggins, as it was not designed to handle concurrent execution of projects (it should properly split messages from different processes in that case)
The easiet workaround is to start several nant processes instead of mixing severl executions in open process/AppDomains. Do you think it is suitable?
Thanks Eugene, I have altered my approach to launch separate processes instead of separate threads and this seems to work with TeamCity.