question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Unhandled exception in ProcessManager when checking process.HasExited

See original GitHub issue

Library name and version

Microsoft.Azure.Services.AppAuthentication 1.0.3

Describe the bug

We use AzureTokenServiceProvider for managed identity in a Azure K8s environment. We observed some exception call stack like below. It seems in the ProcessManager, when checking if (!process.HasExited), it didn’t catch the exception, and eventually can crash the host process.

This happens infrequently. Per Process.HasExited documentation, the InvalidOperationException can be thrown. So I would expect the caller to catch that.

Unhandled exception. System.AggregateException: One or more errors occurred. (No process is associated with this object.)
---> System.InvalidOperationException: No process is associated with this object.
at System.Diagnostics.Process.EnsureState(State state)
at System.Diagnostics.Process.get_HasExited()
at Microsoft.Azure.Services.AppAuthentication.ProcessManager.<>c__DisplayClass2_0.<ExecuteAsync>b__3()
at System.Threading.CancellationToken.<>c.<.cctor>b__26_0(Object obj)
at System.Threading.CancellationTokenSource.CallbackNode.<>c.<ExecuteCallback>b__9_0(Object s)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.CancellationTokenSource.CallbackNode.ExecuteCallback()
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
--- End of inner exception stack trace ---
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
at System.Threading.CancellationTokenSource.NotifyCancellation(Boolean throwOnFirstException)
at System.Threading.CancellationTokenSource.<>c.<.cctor>b__56_0(Object obj)
at System.Threading.TimerQueueTimer.CallCallback(Boolean isThreadPool)
at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
at System.Threading.TimerQueue.FireNextTimers()

Expected behavior

There is no unhandled exception throwing.

Actual behavior

There is an unhandled exception which caused the process to crash.

Reproduction Steps

We don’t have a reproduction steps. This is caught from the production logs when our code consuming this package running in Azure Kubernetes environment.

The environment is our POD consuming the package to get managed identity token based on POD identity framework in Azure Kubernetes cluster. We will use the token to visit our backend Azure SQL server.

Environment

Azure Kubernetes environment based on Ubuntu 1804, dotnet core 3.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
scottaddiecommented, Feb 16, 2022

@shuoshen2014 We’re currently working on a design spec for managed identity token caching in the Azure Identity client libraries. Development on this feature is expected to kick off in the next semester (tentatively, the April/May timeframe).

1reaction
anaismillercommented, Feb 15, 2022

Yes @shuoshen2014 , this is a valid scenario for a bug fix to add “try catch exception” logic around the the process.HasExcited call if it still reproduces in 1.6.2. Feel free to create a PR request against the repo!

Tagging @schaabs and @scottaddie to help/take note on Azure.Identity ask for token caching

Read more comments on GitHub >

github_iconTop Results From Across the Web

If 'Process.HasExited' throws an exception, can I assume ...
Process.HasExited can throw an access denied exception if the target process is running elevated and your process isn't.
Read more >
Process.HasExited Property (System.Diagnostics)
Gets a value indicating whether the associated process has been terminated. ... WaitForExit() overload that takes no parameter before checking HasExited.
Read more >
My application wont close when the code tells it to close C# ...
The app opens, waits a few seconds, and closes again. I get no error. I suspect it's the Timer that's causing it -...
Read more >
Change to photon control between rc9 and final?
Unfortunately there is an exception being thrown when checking the "HasExited" property, because the exit code for the process could not be ...
Read more >
Web - InvalidOperationException occurs in the ...
Process has exited, so the requested information is not available. Description: An unhandled exception occurred during the execution of the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found