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

Insufficient system resources exist to complete requested service #1166

Closed
docjay opened this issue May 6, 2020 · 14 comments
Closed

Insufficient system resources exist to complete requested service #1166

docjay opened this issue May 6, 2020 · 14 comments
Labels

Comments

@docjay
Copy link

docjay commented May 6, 2020

When trying to register a provider in my own project using Microsoft.Diagnostics.Tracing.Session.TraceEventSession.EnableProvider from the Microsoft.Diagnostics.Tracing.TraceEvent nuget package, I get the following exception. The only way I've found to work around it is by restarting my computer. And after restart, I eventually hit the error again. (e.g. restart machine, wait a few days because I forget, then run the application and repro).

Is this known? If unknown, how can I help investigate this issue?

Running Windows OS build 19041.208
Nuget: Microsoft.Diagnostics.Tracing.TraceEvent v2.0.55

-2147023446
Insufficient system resources exist to complete the requested service. (Exception from HRESULT: 0x800705AA)

at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at Microsoft.Diagnostics.Tracing.Session.TraceEventSession.EnsureStarted(EVENT_TRACE_PROPERTIES* properties)
at Microsoft.Diagnostics.Tracing.Session.TraceEventSession.EnableProvider(Guid providerGuid, TraceEventLevel providerLevel, UInt64 matchAnyKeywords, TraceEventProviderOptions options)

@brianrob
Copy link
Member

brianrob commented May 6, 2020

@docjay, based on what you're saying, it sounds like you might have a session leak, meaning that enough sessions are being created that you're unable to create another.

When you hit this error, can you try running logman query -ets and see how many sessions are active? Then, reboot and run the command again. You can compare the output and see which/how many additional sessions are present when things are broken.

@anotheroyz
Copy link

anotheroyz commented Dec 28, 2020

Hit this error when debugging.

There are two scenarios hitting the error System.Runtime.InteropServices.COMException: 'Insufficient system resources exist to complete the requested service. (Exception from HRESULT: 0x800705AA)' in my project.

When I want to get the source of session

eventSession = new TraceEventSession("Test");
ETWTraceEventSource source = eventSession?.Source;

and error occurs

System.Runtime.InteropServices Marshal.ThrowExceptionForHRInternal (Int32 errorCode, IntPtr errorInfo)
Microsoft.Diagnostics.Tracing.Session TraceEventSession.EnsureStarted (EVENT_TRACE_PROPERTIES* properties)
Microsoft.Diagnostics.Tracing.Session TraceEventSession.get_Source ()

And to enable the providers

eventSession = new TraceEventSession("Test");
eventSession?.EnableProvider(new Guid("xxx"));
System.Runtime.InteropServices Marshal.ThrowExceptionForHRInternal (Int32 errorCode, IntPtr errorInfo)
Microsoft.Diagnostics.Tracing.Session TraceEventSession.EnsureStarted (EVENT_TRACE_PROPERTIES* properties)
Microsoft.Diagnostics.Tracing.Session TraceEventSession.EnableProvider (Guid providerGuid, TraceEventLevel providerLevel, UInt64 matchAnyKeywords, TraceEventProviderOptions options)

No more new sessions added.
Capture

@brianrob
Copy link
Member

brianrob commented Jan 5, 2021

@anotheroyz, how many sessions exist when you run logman query -ets?

@anotheroyz
Copy link

It's only 45.

$ logman query -ets | wc -l
45

Is it related to the debugging mode?

Someone in 'Insufficient system resources' when I listen ETW events with EventFlow on ServiceFabric cluster mentioned that each time you start your service, a new session is created, when you do it on Debug mode, the debugger kill the process before it closes the active sessions.

@cgillum
Copy link
Member

cgillum commented Feb 4, 2021

I ran into the same problem, having exactly 45 sessions as well. I didn't create any of these trace sessions myself, so it didn't appear to be caused by something I did.

I temporarily worked around it by killing one of the ETW sessions on the box that seemed expendable. Not sure how safe this actually is...

logman stop Microsoft-VisualStudio-Telemetry-PerfWatson2-37320 -ets

@brianrob
Copy link
Member

brianrob commented Feb 4, 2021

It sounds like you're hitting the maximum number of ETW sessions. I know that VS creates one per VS instance, so if you have a few instances, this can contribute to this issue. But in general, I am seeing more and more sessions being created. I'll pass this along as feedback to the ETW team.

@eladavron
Copy link

Keep running into this as well.
Killing off session doesn't seem to help.

@rosenqui-cysiv
Copy link

Same here... it just started this week for me. It happens when I call TraceEventSession.EnableKernelProvider.

Get-EtwTraceSession * | Measure-Object shows 58 sessions active.

@eladavron
Copy link

eladavron commented Jun 23, 2021

Mine can get as low as 45, but when I start my debugging session it jumps right up to 52 again.
Which doesn't matter, since killing those sessions seems to do nothing.
It's worth mentioning that before it started happening I had an 'unclean' exit, and didn't unregister providers when I quit.
Now I added the destructor:

~MyEventListener()
{
    _session.DisableProvider(_provider.GUID);
}

Which I was hoping would help keep my ETW Trace Sessions clean, but alas it seems to make no difference.
Restarting my computer - weirdly - doesn't help either.

EDIT: I just went nuts and decided "What if I shut ALL of them down?"
Using a hacky PowerShell command (logman query -ets | %{ $_ -split('\s+'); } | %{ logman stop $_ -ets } - it's not great) I just had it shut down everything it could touch - and now the problem's gone. Weird.

@brianrob
Copy link
Member

Restarting should generally solve the problem. If it doesn't, too many sessions are being started on boot, or the issue is something else. It's also worth calling out that logman query -ets doesn't actually list out all sessions - I learned recently that some sessions are hidden. To get the complete list, you can run typeperf -qx "Event Tracing for Windows Session" | findstr /c:"Events Lost". To just get the count, you can run typeperf "Event Tracing for Windows\Total Number of Active Sessions" -sc 1.

@VidyaKukke
Copy link

I'm seeing this too. Is there a way to increase the number of ETW sessions as a workaround? Nothing mentioned here seems to help.

@brianrob
Copy link
Member

brianrob commented Aug 5, 2021

Check out https://devblogs.microsoft.com/performance-diagnostics/wpr-fails-to-start-insufficient-system-resources/. The article talks about why this happens and what you can do to address it.

@VidyaKukke
Copy link

VidyaKukke commented Aug 5, 2021

That was useful article ! Thanks Brian. I was able to cleanup some sessions and removed some from startup.

@brianrob
Copy link
Member

brianrob commented Aug 5, 2021

Excellent @VidyaKukke.

We seem to have built up some critical mass around this problem and have it understood. Given that it is not a PerfView or TraceEvent issue, I'm going to go ahead and close this issue. For those that want more details, please see https://devblogs.microsoft.com/performance-diagnostics/wpr-fails-to-start-insufficient-system-resources/.

@brianrob brianrob closed this as completed Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants