Unobserved task exception in PrometheusHttpListener #5621
Labels
bug
Something isn't working
pkg:OpenTelemetry.Exporter.Prometheus.HttpListener
Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package
Package
OpenTelemetry.Exporter.Prometheus.HttpListener
Package Version
Runtime Version
net6.0
Description
When shutting down a web service which uses a PromethusHttpListener, it is possible to see an unobserved task exception.
HttpListener.GetContextAsync
does not take aCancellationToken
, so thePrometheusHttpListener.WorkerSproc
uses a.Wait
with a cancellation token to handle cancellation. When the token is cancelled, anOperationCancelledException
is thrown from.Wait
which is handled by the loop, but the underlying get context task is not cancelled. Later on in the finally for theWorkerProc
when theHttpListener
is stopped this will cause that task to throw an exception which is then unobserved.I have confirmed that this code has not changed in the most recent branches either.
Steps to Reproduce
Expected Result
PrometheusHttpListener should cleanly shutdown.
Actual Result
Unobserved task exception is thrown.
Additional Context
Stack trace from exception:
The inner exception (
The I/O operation has been aborted because of either a thread exit or an application request.
) is expected when the listener is being shutdown.You can replicate the behavior in LinqPad using something like this. Note that the worker loop exits cleanly, but the ctxTask is faulted and if you don't handle the unobserved exception (which LinqPad does implicitly) you'll see a crash.
The text was updated successfully, but these errors were encountered: