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

Hub.IsEnabled set to false when Hub disposed #1021

Merged
merged 6 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Sentry.Extensibility;
using Sentry.Integrations;
Expand All @@ -19,7 +20,8 @@ internal class Hub : IHub, IDisposable

internal SentryScopeManager ScopeManager { get; }

public bool IsEnabled => true;
private int _isEnabled = 1;
public bool IsEnabled => _isEnabled == 1;

internal Hub(ISentryClient client, SentryOptions options)
{
Expand Down Expand Up @@ -247,6 +249,11 @@ public void Dispose()
{
_options.DiagnosticLogger?.LogInfo("Disposing the Hub.");

if (Interlocked.Exchange(ref _isEnabled, 0) != 1)
{
return;
}

if (_integrations?.Length > 0)
{
foreach (var integration in _integrations)
Expand Down
21 changes: 21 additions & 0 deletions test/Sentry.Tests/HubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,5 +639,26 @@ public void CaptureTransaction_AfterTransactionFinishes_ResetsTransactionOnScope
// Assert
hub.WithScope(scope => scope.Transaction.Should().BeNull());
}

[Theory]
[InlineData(1)]
[InlineData(2)]
public void Dispose_IsEnabled_SetToFalse(int disposeCount)
{
// Arrange
var hub = new Hub(new SentryOptions
{
Dsn = DsnSamples.ValidDsnWithSecret
});

// Act
for (var i = 0; i < disposeCount; i++)
{
hub.Dispose();
}

// Assert
hub.IsEnabled.Should().BeFalse();
semuserable marked this conversation as resolved.
Show resolved Hide resolved
}
}
}