From: Sung Yoon Whang Date: Fri, 7 May 2021 21:54:42 +0000 (-0700) Subject: Make EventPipeSession stop on Dispose (#2259) X-Git-Tag: submit/tizen/20210909.063632~15^2~47 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2eb0cb1b054a5eeb6319d4de486c420b15fb34f8;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Make EventPipeSession stop on Dispose (#2259) * Make EventPipeSession stop on Dispose * catch exceptions thrown from stop --- diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs index 0ca12f92a..9f82f7941 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs @@ -16,7 +16,8 @@ namespace Microsoft.Diagnostics.NETCore.Client private int _circularBufferMB; private long _sessionId; private IpcEndpoint _endpoint; - private bool disposedValue = false; // To detect redundant calls + private bool _disposedValue = false; // To detect redundant calls + private bool _stopped = false; // To detect redundant calls internal EventPipeSession(IpcEndpoint endpoint, IEnumerable providers, bool requestRundown, int circularBufferMB) { @@ -49,6 +50,16 @@ namespace Microsoft.Diagnostics.NETCore.Client public void Stop() { Debug.Assert(_sessionId > 0); + + // Do not issue another Stop command if it has already been issued for this session instance. + if (_stopped) + { + return; + } + else + { + _stopped = true; + } byte[] payload = BitConverter.GetBytes(_sessionId); IpcMessage response; @@ -76,13 +87,23 @@ namespace Microsoft.Diagnostics.NETCore.Client protected virtual void Dispose(bool disposing) { - if (!disposedValue) + // If session being disposed hasn't been stopped, attempt to stop it first + if (!_stopped) + { + try + { + Stop(); + } + catch {} // swallow any exceptions that may be thrown from Stop. + } + + if (!_disposedValue) { if (disposing) { EventStream?.Dispose(); } - disposedValue = true; + _disposedValue = true; } }