-
Notifications
You must be signed in to change notification settings - Fork 734
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
Unobserved task exception in PrometheusHttpListener #5621
Comments
The correct solution here is probably to stop the HttpListener at the same time the token is cancelled (or maybe even just stop using the cancellation token in the worker loop) and handle the HttpListenerException. try
{
// ...
}
catch (HttpListenerException e) when (e.ErrorCode == 995)
{
// Expected exception when HttpListener is shutting down.
} |
@veleek would you share why did you choose "OpenTelemetry" package instead of "OpenTelemetry.Exporter.Prometheus.HttpListener"? I'm trying to see if the issue template needs to be fixed/improved. |
@reyang Nope, no reason. I just totally missed that when filling out the form. Updated now. Thank you! |
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: