BotFramework-Composer icon indicating copy to clipboard operation
BotFramework-Composer copied to clipboard

dotnet build errror when starting a bot project (because it is being used by another process)

Open darrenj opened this issue 3 years ago • 18 comments

Describe the bug

I've seen this a number of times now when switching between different bot projects. Bots start to report errors when starting due to the .exe being used by another process. bot project has only been launched as part of using Composer, VS hasn't been opened against the csproj or anything outside composer.

Digging around in task manager it seems djbfskill6 had a process running in the background, Composer perhaps isn't terminating these processes correctly in some instances?

Error occurred building the bot

Message:
Command failed: dotnet build djbfskill1.csproj
Command:
dotnet build djbfskill1.csproj
Stack Trace:
Error: Command failed: dotnet build djbfskill1.csproj

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
Output:
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj : warning NU1701: Package 'Microsoft.Azure.KeyVault.Core 1.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
  All projects are up-to-date for restore.
C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj : warning NU1701: Package 'Microsoft.Azure.KeyVault.Core 1.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 2 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 3 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 4 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 5 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 6 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 7 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 8 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 9 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 10 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): error MSB3027: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Exceeded retry count of 10. Failed.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): error MSB3021: Unable to copy file "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process. [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]

Build FAILED.

C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj : warning NU1701: Package 'Microsoft.Azure.KeyVault.Core 1.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj : warning NU1701: Package 'Microsoft.Azure.KeyVault.Core 1.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 2 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 3 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 4 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 5 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 6 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 7 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 8 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 9 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): warning MSB3026: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Beginning retry 10 in 1000ms. The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): error MSB3027: Could not copy "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". Exceeded retry count of 10. Failed.  [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]
C:\Program Files\dotnet\sdk\5.0.201\Microsoft.Common.CurrentVersion.targets(4919,5): error MSB3021: Unable to copy file "C:\Users\darrenj\djbfskill1\djbfskill1\obj\Debug\netcoreapp3.1\apphost.exe" to "bin\Debug\netcoreapp3.1\djbfskill1.exe". The process cannot access the file 'C:\Users\darrenj\djbfskill1\djbfskill1\bin\Debug\netcoreapp3.1\djbfskill1.exe' because it is being used by another process. [C:\Users\darrenj\djbfskill1\djbfskill1\djbfskill1.csproj]

Version

1.4.0-nightly.237101

Browser

  • [x] Electron distribution
  • [ ] Chrome
  • [ ] Safari
  • [ ] Firefox
  • [ ] Edge

OS

  • [ ] macOS
  • [x] Windows
  • [ ] Ubuntu

darrenj avatar Apr 20 '21 14:04 darrenj

By "switching bot projects" do you mean, open bot1, start bot1, and switch to bot2 and back to bot1, then start again?

boydc2014 avatar Apr 20 '21 23:04 boydc2014

note: seems to be an issue with the new runtime

boydc2014 avatar Apr 21 '21 00:04 boydc2014

Now I have 3 dangling processes with Composer closed and no bugs hit:

image

scheyal avatar Apr 22 '21 22:04 scheyal

Sorry, by switching between Bots I meant different bot projects

darrenj avatar Apr 28 '21 13:04 darrenj

Passing P0 from closed dup here for consideration.

scheyal avatar May 03 '21 16:05 scheyal

Shiproom - Tony is working on a similar issue that relates to this. depending on that issue, we'll decide on this issue.

sgellock avatar May 04 '21 15:05 sgellock

I am also able to repro this by doing the following:

  1. Create / Open bot
  2. Start bot
  3. Install package while bot is running
  4. Try to start bot
  5. Observe errors
  6. Starting bot again is successful

Related: #7498, #7114

tonyanziano avatar May 04 '21 16:05 tonyanziano

After some investigation, it seems like the package manager extension is calling reloadProject() which does not actually stop the currently running bot. However, the correct behavior -- which is observed when switching bot projects, is to call stopBot().

This is a limitation of the shell API which does not expose the ability to stop a bot to the extensions.

tonyanziano avatar May 04 '21 22:05 tonyanziano

Shiproom - approved

sgellock avatar May 07 '21 16:05 sgellock

Shiproom - PR merged. Closing the issue.

sgellock avatar May 07 '21 23:05 sgellock

@srinaath - I still see the dangling process in today's build. Is that supposed to be fixed?

[BF]c:\workspace\botroot\TempPlay>tasklist | findstr /i teletest
TeleTest.exe                 48360 Console                    3    421,520 K
TeleTest.exe                  7308 Console                    3     71,276 K

Version: 2.0.0-nightly.243997.543d0b4 Electron: 8.2.4 Chrome: 80.0.3987.165 NodeJS: 12.13.0 V8: 8.0.426.27-electron.0

scheyal avatar May 10 '21 18:05 scheyal

Shiproom - since this was reopened, I've removed the approved label.

sgellock avatar May 10 '21 19:05 sgellock

Shiproom - we've fixed some of these scenarios. At this point, I'm moving this out of R13 for consideration in a post build release

sgellock avatar May 10 '21 20:05 sgellock

let's use this ticket to track a better cleanup approach for all processes like what VSCode do.

boydc2014 avatar May 28 '21 00:05 boydc2014

I spiked out a PoC of a mechanism that would allow the Electron main process to wait for asynchronous cleanup tasks on the renderer process before shutting down.

You can find the source here.

Now it's just a matter of deciding whether it's something we want to use or modify and then porting it over to Composer. We would then be able to wait for running bots to be shut down by this mechanism before closing Composer.

tonyanziano avatar Jun 04 '21 00:06 tonyanziano

I spiked out a PoC of a mechanism that would allow the Electron main process to wait for asynchronous cleanup tasks on the renderer process before shutting down.

You can find the source here.

Now it's just a matter of deciding whether it's something we want to use or modify and then porting it over to Composer. We would then be able to wait for running bots to be shut down by this mechanism before closing Composer.

Awesome demo of the POC, it looks very promising. In terms of timeline, at this moment i don't think we have resource to include this in R14, what do you think? How about we move this to R15?

boydc2014 avatar Jun 17 '21 10:06 boydc2014

@boydc2014 I agree. Let's move it to R15.

Here are some notes from the team's previous meeting about the feature:

  • Need to test this with auto update -- will calls to installAndUpdate(), which closes all the app windows, trigger the shutdown logic?

  • Need to consider handling force quits (Alt + F4 / Task Manager on Windows -- Mac equivalent)

    • Can catch UNIX signals: process.on('SIGINT', () => { doCleanup() });
    • This should be cross-platform as well
  • Blocking client on cleanup could be annoying without some sort of status / progress screen (Shutting down...)

    • Teams used to do this in the early days and it was annoying
    • We could also add a timeout that eventually force quits the app if the shutdown is taking too long

tonyanziano avatar Jun 17 '21 23:06 tonyanziano

Regarding auto update compatibility, from the electron-updater source:

Note: autoUpdater.quitAndInstall() will close all application windows first and only emit before-quit event on app after that.

This should hit the clean-up logic.

tonyanziano avatar Jul 06 '21 18:07 tonyanziano

There was some work done to improve this. I believe this is fixed. Feel free to reopen if not

OEvgeny avatar Feb 27 '24 19:02 OEvgeny