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

Make the SDK more forgiving for ObjectDisposedException #3291

Merged
merged 3 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 24 additions & 3 deletions src/OpenTelemetry/BatchExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ protected override void OnExport(T data)
{
if (this.circularBuffer.Count >= this.maxExportBatchSize)
{
this.exportTrigger.Set();
try
{
this.exportTrigger.Set();
}
catch (ObjectDisposedException)
{
}
}

return; // enqueue succeeded
Expand All @@ -121,7 +127,14 @@ protected override bool OnForceFlush(int timeoutMilliseconds)
return true; // nothing to flush
}

this.exportTrigger.Set();
try
{
this.exportTrigger.Set();
}
catch (ObjectDisposedException)
{
return false;
}

if (timeoutMilliseconds == 0)
{
Expand Down Expand Up @@ -186,7 +199,15 @@ protected override bool OnForceFlush(int timeoutMilliseconds)
protected override bool OnShutdown(int timeoutMilliseconds)
{
this.shutdownDrainTarget = this.circularBuffer.AddedCount;
this.shutdownTrigger.Set();

try
{
this.shutdownTrigger.Set();
}
catch (ObjectDisposedException)
{
return false;
}

OpenTelemetrySdkEventSource.Log.DroppedExportProcessorItems(this.GetType().Name, this.exporter.GetType().Name, this.droppedCount);

Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

* Fix null reference exception when a metric view does not match an instrument.
([#3285](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3285))
* Swallow `ObjectDisposedException` in `BatchExportProcessor` and
* `PeriodicExportingMetricReader`.
([#3291](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3291))

## 1.3.0-beta.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ protected override bool OnShutdown(int timeoutMilliseconds)
{
var result = true;

this.shutdownTrigger.Set();
try
{
this.shutdownTrigger.Set();
}
catch (ObjectDisposedException)
{
return false;
}

if (timeoutMilliseconds == Timeout.Infinite)
{
Expand Down