This project is read-only.
2

Closed

Issue with AsyncExec task

description

Hi, I seem to be getting an internal error with the AsynxExec task. It is intermittent.

From the build log - on this occasion I happen to be trying to execute a batch file in this example, but it fails with the same error on other tasks. I'm using version 3.5

Am I the only one with this issue ?

Using "MSBuild.ExtensionPack.Framework.AsyncExec" task from assembly "E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\MSBuild.ExtensionPack.dll".
Task "MSBuild.ExtensionPack.Framework.AsyncExec"
Command: E:\Source\PsTools\psexec.exe -accepteula \NWPAPPFSTU10 -u nwp-biz\svc-nwptfssrv -p ?3x0du10 -i -high cmd /c "E:\BatchScripts\BuildScripts\42\CleanFASTCollections.bat" RUSSIAC AUSTRIAC RXRUC IBERIAC ITALYC
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: The "MSBuild.ExtensionPack.Framework.AsyncExec" task failed unexpectedly. [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: System.IO.IOException: Cannot create a file when that file already exists. [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: at System.IO.__Error.WinIOError() [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: at System.IO.File.Move(String sourceFileName, String destFileName) [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: at MSBuild.ExtensionPack.Framework.AsyncExec.CreateBatchProgram(String command) in D:\Projects\MSBuildExtensionPack\Releases\4.0.3.0\Main\Framework\Framework\AsyncExec.cs:line 107 [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: at MSBuild.ExtensionPack.Framework.AsyncExec.<Execute>b__2(String command) in D:\Projects\MSBuildExtensionPack\Releases\4.0.3.0\Main\Framework\Framework\AsyncExec.cs:line 70 [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: at MSBuild.ExtensionPack.Framework.AsyncExec.Execute() in D:\Projects\MSBuildExtensionPack\Releases\4.0.3.0\Main\Framework\Framework\AsyncExec.cs:line 70 [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\CleanFASTCollections.targets(29,5): warning MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult) [E:\Builds\42\NOVA Platform\v2.10.2-Demo\BuildType\TFSBuild.proj]
The previous error was converted to a warning because the task was called with ContinueOnError=true.
Build continuing because "ContinueOnError" on the task "MSBuild.ExtensionPack.Framework.AsyncExec" is set to "true".
Done executing task "MSBuild.ExtensionPack.Framework.AsyncExec" -- FAILED.
Closed Apr 20, 2014 at 2:38 PM by mikeFourie

comments

mikeFourie wrote Oct 9, 2013 at 9:26 PM

Its some sort of race condition.

CleanFASTCollections.targets(29,5): warning MSB4018: System.IO.IOException: Cannot create a file when that file already exists.

Take a look at what is happening CleanFASTCollections.targets(29,5).

It's hard to provide a solution for something like this. Basically you'll need to see if something can be written to work better in parallel or you will need to run part of the build in sequence.

Mike

wrote Oct 9, 2013 at 9:26 PM

BrianButler wrote Apr 17, 2014 at 8:18 PM

This is a bug in AsyncExec. Specifically in CreateBatchProgram. The file created by GetTempFileName() is guaranteed to be unique at the time of creation. However, by renaming the file to .bat the old filename can be reused without violating this contract. When you go to rename again (with Move) there is a conflict, and the error reported here.

For example...
AsyncExec #1
GetTempFileName picks file0001.tmp. It's unused so it returns this file.
Move renames to file0001.tmp.bat
AsyncExec #2
GetTempFileName picks file0001.tmp. It's unused so it returns this file.
Move tries to rename to file0001.tmp.bat and FAILS.

Without the rename in AsyncExec #1, AsyncExec #2 looks like this:
GetTempFileName picks file0001.tmp. It's used, so increment to file0002.tmp. That one is unused so it returns this file.

mikeFourie wrote Apr 17, 2014 at 11:57 PM

** Closed by mikeFourie 09/10/2013 13:26

wrote Apr 17, 2014 at 11:57 PM

mikeFourie wrote Apr 17, 2014 at 11:57 PM

Thanks, I'll take a look... Mike

BrianButler wrote Apr 18, 2014 at 10:15 PM

To workaround, I switched the Move to a Copy (with overwrite=true). This leaves a 0-byte .tmp file so that GetTempFileName will be forced to pick a unique name. It's not ideal; I'd prefer a GetTempFileName method that gave us .bat directly, but I think even the Win32 version won't do that. It would have to be re-implemented.

wrote Apr 18, 2014 at 11:00 PM

wrote Apr 20, 2014 at 2:37 PM

wrote Apr 20, 2014 at 2:38 PM

Resolved with changeset 88004: Framework\AsyncExec.cs: Fix for file generation

wrote Nov 27 at 8:35 PM