Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a program is terminated by unhandled exception, its OS process remains #102568

Closed
wsy opened this issue May 22, 2024 · 14 comments
Closed

If a program is terminated by unhandled exception, its OS process remains #102568

wsy opened this issue May 22, 2024 · 14 comments
Assignees
Labels
area-Diagnostics-coreclr needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone

Comments

@wsy
Copy link

wsy commented May 22, 2024

Description

If a program gets terminated by unhandled exception, the underlying OS process will not be terminated as expected.

Reproduction Steps

  1. Write a simple dotnet program which throws an exception. Then compile it as "sample.exe".
// Sample.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
</Project>
// Program.cs
using System;

Console.WriteLine("Hello, World!");
// Application is terminated by exception,
// process will (but should not)
// remain in taskmgr.exe
throw new Exception();
  1. Execute "sample.exe".
  2. In taskmgr.exe, see if "sample.exe" has disappeared.
  3. Try to delete "sample.exe".

Expected behavior

  1. "sample.exe" should be terminated by "Unhandled exception".
  2. "sample.exe" should disappear from taskmgr.exe
  3. Delete operation should be successful.

Actual behavior

  1. "sample.exe" is terminated by "Unhandled exception" as expected.
  2. "sample.exe" still exists in taskmgr.exe with status "Suspended" and "Commit size" almost same as it was when the program was running.
  3. Delete operation failed with error message "File In Use"

image

Further operation:

  1. If you try to kill process "sample.exe", you will "succeed" for the first time.

  2. However, the process "sample.exe" is still shown in taskmgr.exe with "Commit Size" of "84K". (No matter how much memory was requested before program exited.)

  3. If you try to kill process "sample.exe" again, you will get "Access denied" error.
    image

  4. If you try to delete "sample.exe" at this time, file delete operation will succeed. However, the process still remains in taskmgr.exe
    image

Regression?

No response

Known Workarounds

No response

Configuration

.NET version: 8.x, 7.x, 6.x
OS: Windows 11 22621.3593
Architecture: x64

Other information

I tried this in Windows Sandbox, which should be a clean environment.
I first noticed this bug with .Net 8. However, when I was taking screenshots for this bug report, I tried with .Net7 and .Net6 and this bug can still be re-produced.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 22, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 22, 2024
@jkotas jkotas added area-Diagnostics-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 22, 2024
@wsy
Copy link
Author

wsy commented May 24, 2024

I tried this on another Windows 11 machine and I got same result.

I also tried this on Windows Server 2022, and this problem does not exist.

Back in year 2022, when I was using .Net 6 with Windows 10, I never noticed this issue. So I guess this problem only happens on Windows 11. I will install a virtual machine and try this on older Windows 11 versions. I will report later.

Another detail that I noticed: I saw two processes in Task Manager and one of them (with state 'Running') exited normally while another one (with state 'Suspend') remained in Task Manager.

@danmoseley
Copy link
Member

Can you try with .NET Framework as well?

@wsy
Copy link
Author

wsy commented May 25, 2024

Hi @danmoseley ,
I tried and this bug can be re-produced with .NET Framework.
Same result, and I saw two "Program.exe" processes in Task Manager.
image

@wsy
Copy link
Author

wsy commented May 25, 2024

I tried Windows 11 21H2 ver 22000.675 with built-in .NET Framework 4.8.4161.
I can see when exception is thrown, a second process showed in Task Manager with state "Suspended". This is same as my Windows 11 22H2 ver 22621.3593. But the second process would exit alongside with the original process.

@tommcdon tommcdon self-assigned this May 28, 2024
@tommcdon tommcdon added this to the 9.0.0 milestone May 28, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label May 28, 2024
@tommcdon
Copy link
Member

tommcdon commented Jun 5, 2024

Hi @wsy! The "suspended" process is likely an artifact of Windows Error Reporting (WER) collecting a dump of the process after the unhandled exception. In task manager, please determine if there is a werfault.exe running at the same time as the suspended process exists. After WER completes, the secondary process should go away. Hope this helps, and please let us know if this answers the question!

@tommcdon tommcdon added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 5, 2024
@wsy
Copy link
Author

wsy commented Jun 12, 2024

Hi @wsy! The "suspended" process is likely an artifact of Windows Error Reporting (WER) collecting a dump of the process after the unhandled exception. In task manager, please determine if there is a werfault.exe running at the same time as the suspended process exists. After WER completes, the secondary process should go away. Hope this helps, and please let us know if this answers the question!

Hi @tommcdon ,
Sorry for the delay. Today I tried in my Windows Sandbox with dotnet 8.0.
After the exception has been thrown, the second process showed up in Task Manager together with werfault.exe.
However, werfault.exe quickly disappeared while the second process remained.

@dotnet-policy-service dotnet-policy-service bot added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Jun 12, 2024
@CyrusNajmabadi
Copy link
Member

FWIW, i've been running into this a lot. Processes left behind int eh suspended state, never fully closing down. Perhaps it's a werfault issue? They do some reporting, but then don't properly clean up once done?

@wsy
Copy link
Author

wsy commented Jun 13, 2024

FWIW, i've been running into this a lot. Processes left behind int eh suspended state, never fully closing down. Perhaps it's a werfault issue? They do some reporting, but then don't properly clean up once done?

Hi,
If this is werfault issue, how do we report this issue? And to whom shall we report this issue to?

@wsy
Copy link
Author

wsy commented Jun 13, 2024

Hi @CyrusNajmabadi ,
I tried with a C program (code below).
And this program can re-produce this bug. When this program exited, a process with suspended state remained in Task Manager.
Now I think it's very likely a werfault issue.

int main()
{
  int *p = 0;
  int e = *p;
  return 0;
}

@tommcdon
Copy link
Member

Hi, If this is werfault issue, how do we report this issue? And to whom shall we report this issue to?

I'll be happy to report it to the WER team. Doing some quick research it seems that the suspended process might caused by leaving task manager open. @wsy would you mind trying to close task manager, then re-open it to see if the suspended/defunct process is still there?

@wsy
Copy link
Author

wsy commented Jun 15, 2024

Hi, If this is werfault issue, how do we report this issue? And to whom shall we report this issue to?

I'll be happy to report it to the WER team. Doing some quick research it seems that the suspended process might caused by leaving task manager open. @wsy would you mind trying to close task manager, then re-open it to see if the suspended/defunct process is still there?

Hi,
I tried this just now.
The suspended process disappeared after I close taskmgr.
So, is this a taskmgr issue or werfault issue?
It seems I will have to suspend my habit of 'keeping taskmgr open forever' until Windows team fix this?

@wsy
Copy link
Author

wsy commented Jun 15, 2024

By the way, I have to say, the new taskmgr is really far away from the word 'stable'.
I have a habit of opening taskmgr all the time (minimized to system tray) while my computer is running. I have had this habit since Windows XP.
And since Windows 11, the new taskmgr is significantly slower than its Windows 10 ancestor. Also, it would become unresponsive after running for days.

@tommcdon
Copy link
Member

@wsy I suggest reporting the task manager issue using the Feedback Hub tool in Windows - https://go.microsoft.com/fwlink/?linkid=760672. This will help ensure the problem will be routed to the right team and will be tracked properly. Since this is not a dotnet specific problem, I will close this issue.

@wsy
Copy link
Author

wsy commented Jun 17, 2024

Well, during the weekends, I installed some Windows updates.

Just now, I opened Windows Feedback app and filled out the form.

Then I tried to reproduce the bug so that I could take screenshots of them.

However the bug disappeared. Maybe it's already fixed in those updates I installed during the weekends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Diagnostics-coreclr needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
None yet
Development

No branches or pull requests

5 participants