locked
TFS 2017 Windows Machine File Copy task - robocopy fails with System error 32 RRS feed

  • Question

  • The error (log below) is claiming that the .dll is being used by another process, but ProcessExplorer wasn't able to locate this file lock, checked in both DLL and Handle mode. I then thought that it could be maybe be Sophos antivirus, as it would scan the files downloaded to release folder during the 'Download Artifacts' stage of the release, but I've disabled Sophos and the issue remained. After maybe 25 retries (13 min), the file becomes unlocked by itself and robocopy is able to move it. I'm beginning to think this is an issue with Windows Machine file copy task locking itself, but I haven't seen any other articles on this. I can't see any other processes running on the build server that would interfere (windows server 2012 R2).

    Any help, suggestions, or troubleshooting methods would be helpful.

    2017-08-30T19:40:39.2948269Z ##[section]Starting: Deploy to Web Server
    2017-08-30T19:40:39.3260740Z ==============================================================================
    2017-08-30T19:40:39.3260740Z Task         : Windows Machine File Copy
    2017-08-30T19:40:39.3260740Z Description  : Copy files to remote machine(s)
    2017-08-30T19:40:39.3260740Z Version      : 1.0.39
    2017-08-30T19:40:39.3260740Z Author       : Microsoft Corporation
    2017-08-30T19:40:39.3260740Z Help         : [More Information]
    2017-08-30T19:40:39.3260740Z ==============================================================================
    2017-08-30T19:40:39.3416965Z Preparing task execution handler.
    2017-08-30T19:40:39.8573258Z Executing the powershell script: C:\Agent\_work\_tasks\WindowsMachineFileCopy_731004d4-1d66-4f70-8c05-638018b22210\1.0.39\WindowsMachineFileCopy.ps1
    2017-08-30T19:40:41.2323468Z Copy started for - 'server'
    2017-08-30T19:40:43.0917080Z
    2017-08-30T19:40:43.0917080Z  Log File : C:\Agent\logs\robocopy-log.txt
    2017-08-30T19:40:43.0917080Z
    2017-08-30T19:40:43.0917080Z -------------------------------------------------------------------------------
    2017-08-30T19:40:43.0917080Z    ROBOCOPY     ::     Robust File Copy for Windows                             
    2017-08-30T19:40:43.0917080Z -------------------------------------------------------------------------------
    2017-08-30T19:40:43.0917080Z
    2017-08-30T19:40:43.0917080Z   Started : Wednesday, August 30, 2017 2:40:43 PM
    2017-08-30T19:40:43.0917080Z    Source : 'removed'
    2017-08-30T19:40:43.0917080Z      Dest : 'removed'
    2017-08-30T19:40:43.0917080Z
    2017-08-30T19:40:43.0917080Z     Files : *.*
    2017-08-30T19:40:43.0917080Z     
    2017-08-30T19:40:43.0917080Z Exc Files : web.config
    2017-08-30T19:40:43.0917080Z     
    2017-08-30T19:40:43.0917080Z   Options : *.* /V /FP /TEE /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30
    2017-08-30T19:40:43.0917080Z
    2017-08-30T19:40:43.0917080Z ------------------------------------------------------------------------------
    2017-08-30T19:40:43.1073396Z

    2017-08-30T19:40:43.2010872Z      Newer            622 C:\Agent\_work\r2\a\'removed'\Publish\bundleconfig.json
    2017-08-30T19:40:43.2167170Z   0% 
    2017-08-30T19:40:43.2167170Z 100% 
    2017-08-30T19:40:43.2323358Z      Newer         719872 C:\Agent\_work\r2\a\'removed'\bin\Release\netcoreapp1.1\Publish\CoreCompat.System.Drawing.dll
    2017-08-30T19:40:43.2323358Z 2017/08/30 14:40:43 ERROR 32 (0x00000020) Copying File C:\Agent\_work\r2\a\'removed'\bin\Release\netcoreapp1.1\Publish\CoreCompat.System.Drawing.dll
    2017-08-30T19:40:43.2323358Z The process cannot access the file because it is being used by another process.
    2017-08-30T19:40:43.2323358Z
    2017-08-30T19:41:13.2480350Z Waiting 30 seconds... Retrying...

    2017-08-30T19:40:43.2323358Z      Newer         719872 C:\Agent\_work\r2\a\'removed'\bin\Release\netcoreapp1.1\Publish\CoreCompat.System.Drawing.dll
    2017-08-30T19:40:43.2323358Z 2017/08/30 14:40:43 ERROR 32 (0x00000020) Copying File C:\Agent\_work\r2\a\'removed'\bin\Release\netcoreapp1.1\Publish\CoreCompat.System.Drawing.dll
    2017-08-30T19:40:43.2323358Z The process cannot access the file because it is being used by another process.
    2017-08-30T19:40:43.2323358Z
    2017-08-30T19:41:13.2480350Z Waiting 30 seconds... Retrying...

    Wednesday, August 30, 2017 9:12 PM

Answers

  • hi deviljim,

    your are deploying to a Web Server and therefore it is very likely that the file is locked by IIS.

    to test it, manually stop the web site and try to deploy again.

    if it works than you need to notify IIS to take the web site offline while deploying - using WebDeploy you nave the option to automatically take the web site offline. if you manually deploy the files using robocopy than you need to copy first a special named file app_offline.htm


    Please use "Mark as Answer" if my post solved your problem and use "Vote As Helpful" if a post was useful.

    • Marked as answer by deviljim Monday, September 25, 2017 2:46 PM
    Friday, September 8, 2017 7:12 PM

All replies

  • Hi,

    File or folder in use errors are often indicated by error messages such as:

    • Access to the path [...] is denied.
    • The process cannot access the file [...] because it is being used by another process.
    • Access is denied.
    • Can't move [...] to [...]

    Detect files and folders in use
    On Windows, tools like Process Monitor can be to capture a trace of file events under a specific directory. Or, for a snapshot in time, tools like Process Explorer or Handle can be used.

    Anti-virus exclusion
    Anti-virus software scanning your files can cause file or folder in use errors during a build. Adding an anti-virus exclusion for your agent directory and configured "work folder" may help to identify anti-virus software as the interfering process.

    More details, check the link below:

    https://www.visualstudio.com/en-us/docs/build/troubleshooting#file--and-folder-in-use-errors

    Best regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, August 31, 2017 7:50 AM
  • Hi Xinxin,

    I've already tried your suggestions, disabled the anti-virus and still no avail. Process Monitor/Explorer do not indicate these files are being accessed, in fact I'm able to even delete/move the locked files in question while robocopy is running. I shouldn't be able to if they were truly locked.

    Thursday, September 7, 2017 10:22 PM
  • Hi,

    Do you invoke MSBuild during your build? You may also try to pass the argument /nr:false and /m:1 for your build task as the article mentioned.

    Best regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by deviljim Friday, September 15, 2017 7:45 PM
    • Unmarked as answer by deviljim Friday, September 15, 2017 9:28 PM
    Friday, September 8, 2017 9:34 AM
  • hi deviljim,

    your are deploying to a Web Server and therefore it is very likely that the file is locked by IIS.

    to test it, manually stop the web site and try to deploy again.

    if it works than you need to notify IIS to take the web site offline while deploying - using WebDeploy you nave the option to automatically take the web site offline. if you manually deploy the files using robocopy than you need to copy first a special named file app_offline.htm


    Please use "Mark as Answer" if my post solved your problem and use "Vote As Helpful" if a post was useful.

    • Marked as answer by deviljim Monday, September 25, 2017 2:46 PM
    Friday, September 8, 2017 7:12 PM
  • I've added these flags to the MSBuild task but the issue remained. 

    Also  I do not see any MSBuild.exe processes running during TFS release task (robocopy) so I don't think MSBuild is the issue.

    This file was indeed locked by IIS during webdeploy, the fix is shutting down the application pool via script. Thanks for the assistance.


    • Edited by deviljim Monday, September 25, 2017 2:49 PM
    Friday, September 15, 2017 10:04 PM