Skip to content

Commit

Permalink
Don't dispose hub in unhandled exception handler (#1794)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Jul 21, 2022
1 parent dcdef22 commit 6b9f329
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Fix error with `ConcurrentHashMap` on Android <= 9 ([#1761](https://github.com/getsentry/sentry-dotnet/pull/1761))
- Minor improvements to `BackgroundWorker` ([#1773](https://github.com/getsentry/sentry-dotnet/pull/1773))
- Make GzipRequestBodyHandler respect async ([#1776](https://github.com/getsentry/sentry-dotnet/pull/1776))
- Fix exceptions on background thread not reported in Unity ([#1794](https://github.com/getsentry/sentry-dotnet/pull/1794))

## 3.19.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ internal class AppDomainUnhandledExceptionIntegration : ISdkIntegration
{
private readonly IAppDomain _appDomain;
private IHub? _hub;
private SentryOptions? _options;

internal AppDomainUnhandledExceptionIntegration(IAppDomain? appDomain = null)
=> _appDomain = appDomain ?? AppDomainAdapter.Instance;

public void Register(IHub hub, SentryOptions _)
public void Register(IHub hub, SentryOptions options)
{
_hub = hub;
_options = options;
_appDomain.UnhandledException += Handle;
}

Expand All @@ -36,7 +38,7 @@ internal void Handle(object sender, UnhandledExceptionEventArgs e)

if (e.IsTerminating)
{
(_hub as IDisposable)?.Dispose();
_hub?.FlushAsync(_options!.ShutdownTimeout).GetAwaiter().GetResult();
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions test/Sentry.Tests/AppDomainUnhandledExceptionIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ public void Handle_NoException_NoCaptureEvent()
}

[Fact]
public void Handle_TerminatingTrue_DisposesHub()
public void Handle_TerminatingTrue_FlushesHub()
{
var sut = _fixture.GetSut();
sut.Register(_fixture.Hub, SentryOptions);

sut.Handle(this, new UnhandledExceptionEventArgs(new Exception(), true));

var disposableHub = _fixture.Hub as IDisposable;
disposableHub.Received(1).Dispose();
_fixture.Hub.Received(1).FlushAsync(Arg.Any<TimeSpan>());
}

[Fact]
Expand All @@ -70,15 +69,14 @@ public void Handle_TerminatingTrue_IsHandledFalse()
}

[Fact]
public void Handle_TerminatingTrue_NoException_DisposesHub()
public void Handle_TerminatingTrue_NoException_FlushesHub()
{
var sut = _fixture.GetSut();
sut.Register(_fixture.Hub, SentryOptions);

sut.Handle(this, new UnhandledExceptionEventArgs(null, true));

var disposableHub = _fixture.Hub as IDisposable;
disposableHub.Received(1).Dispose();
_fixture.Hub.Received(1).FlushAsync(Arg.Any<TimeSpan>());
}

[Fact]
Expand Down

0 comments on commit 6b9f329

Please sign in to comment.