Windows Service Deployment Process always fails in 1st attempt

Hi,

I am using OD Server v3.0.19.2485 and Tentacle v3.0.19.2485 to deploy to a Windows Server 2012 R2 (64-bit) machine.

We have a process with 1 step “Deploy NuGet package” that install a Windows Service in a Custom Directory.

When the process run for the first time in the machine, with had no problems (the service was not installed yet).

Now, every-time we deploy a new release we get the error bellow.

Right after it fails, if we retry again… it succeeds!

Can it be that this file lock issue is because, the service is still running when the files are being deployed?

Can you please assist us?

Cheers,
Carlos

#######################################################################################################
Copying package contents to ‘D:\Jobs\WindowsService’

10:38:27

Error
System.IO.IOException: The process cannot access the file ‘D:\Jobs\WindowsService\FILE.dll’ because it is being used by another process.

10:38:28

Error
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

10:38:28

Error
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)

10:38:28

Error
at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.CopyFile(String sourceFile, String targetFile, Int32 overwriteFileRetryAttempts) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 365

10:38:28

Error
at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.CopyDirectory(String sourceDirectory, String targetDirectory, CancellationToken cancel, Int32 overwriteFileRetryAttempts) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 340

10:38:28

Error
at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.CopyDirectory(String sourceDirectory, String targetDirectory, Int32 overwriteFileRetryAttempts) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 321

10:38:28

Error
at Calamari.Deployment.Conventions.CopyPackageToCustomInstallationDirectoryConvention.Install(RunningDeployment deployment) in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\Conventions\CopyPackageToCustomInstallationDirectoryConvention.cs:line 40

10:38:28

Error
at Calamari.Deployment.ConventionProcessor.RunInstallConventions() in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\ConventionProcessor.cs:line 60

10:38:28

Error
at Calamari.Deployment.ConventionProcessor.RunConventions() in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\ConventionProcessor.cs:line 28

10:38:28

Error
Running rollback conventions…

10:38:28

Error
System.IO.IOException: The process cannot access the file ‘D:\Jobs\PaymentPlansDispatcherService\DA.Core.dll’ because it is being used by another process.

10:38:28

Error
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

10:38:28

Error
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)

10:38:28

Error
at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.CopyFile(String sourceFile, String targetFile, Int32 overwriteFileRetryAttempts) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 365

10:38:28

Error
at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.CopyDirectory(String sourceDirectory, String targetDirectory, CancellationToken cancel, Int32 overwriteFileRetryAttempts) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 340

10:38:28

Error
at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.CopyDirectory(String sourceDirectory, String targetDirectory, Int32 overwriteFileRetryAttempts) in y:\work\b1fd300731d5f2fc\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 321

10:38:28

Error
at Calamari.Deployment.Conventions.CopyPackageToCustomInstallationDirectoryConvention.Install(RunningDeployment deployment) in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\Conventions\CopyPackageToCustomInstallationDirectoryConvention.cs:line 40

10:38:28

Error
at Calamari.Deployment.ConventionProcessor.RunInstallConventions() in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\ConventionProcessor.cs:line 60

10:38:28

Error
at Calamari.Deployment.ConventionProcessor.RunConventions() in y:\work\b1fd300731d5f2fc\source\Calamari\Deployment\ConventionProcessor.cs:line 50

10:38:28

Error
at Calamari.Commands.DeployPackageCommand.Execute(String[] commandLineArguments) in y:\work\b1fd300731d5f2fc\source\Calamari\Commands\DeployPackageCommand.cs:line 107

10:38:28

Error
at Calamari.Program.Main(String[] args) in y:\work\b1fd300731d5f2fc\source\Calamari\Program.cs:line 21

10:38:28

Error
The remote script failed with exit code 100

I also used the Windows Service - Stop task (from the community) and placed it as 1st step… I get:

Stopping SERVICE…

11:40:32

Info
Service SERVICE stopped.

To make sure the service is stopped. But, it did not solve the problem.

Carlos,

Sorry you are having a problem here, hopefully I can help.

Even after a Windows Service has been asked to stop and says it has stopped, Windows allows the service to keep going for up to about 30 seconds so it can shutdown background threads. A well-written service should be able to shut down all threads in a timely manner. Needless to say many services don’t do this and Windows often waits the full 30s before killing it. Stack Overflow has some advice on this here:- http://stackoverflow.com/questions/1528209/how-to-properly-stop-a-multi-threaded-net-windows-service although many of the answers pre-date CancellationTokenSource which is a cleaner way to shutdown many sub-systems now.

Knowing that many services will claim to have stopped but will need the extra 30 seconds, we recently bumped up the retry loop for CopyFile so that it would keep trying for almost a minute. If you open the log for this deployment and click Verbose does it show multiple retries? Please could you post that section of the log so we can see for how long it is trying.

Regards,

Ian Mercer

Hi Ian,

Problem solved! You are right. I am now canceling my worker thread onStop() of the Windows Service… and I don’t get this issue anymore.

I followed this tutorial: http://stackoverflow.com/questions/4783865/how-do-i-abort-cancel-tpl-tasks