microsoft / ApplicationInsights-Profiler-AspNetCore

Application Insights Profiler sample and documentation
MIT License
66 stars 22 forks source link

EventPipe session was not disposed upon stopping exception #208

Open xiaomi7732 opened 7 months ago

xiaomi7732 commented 7 months ago

Describe the bug Event pipe session isn't disposed when there's exception.

To Reproduce Steps to reproduce the behavior:

For whatever reason, when there's exception, the event pipe session should be disposed upon stopping.

Expected behavior Dispose being called upon exception.

...
                try
                {
                    if (_currentSession != null)
                    {
                        _...

                        if (disposeEventSessionImmediately)
                        {
                            DisposeEventPipeSession();
                        }
                    }

                    _logger.LogTrace("[{typeName}] Disabled.", _typeName);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Unexpected exception stopping session.");
                    // !!!!!! Dispose should have been called here !!!!!!!
                    throw;
                }
                finally
                {
                    _singleTraceSessionHandle.Release();
                }

The same should be done for start logic.