csharp icon indicating copy to clipboard operation
csharp copied to clipboard

Unobserved Task exception from k8s.LineSeparatedHttpContent.CancelableStream.ReadAsync after Upgrade

Open aukevin opened this issue 3 months ago • 4 comments

I'm working on a series of package upgrades from an old project. In this case I'm trying to upgrade the KubernetesClient package from 3.0.7 to 17.0.4. This was done mainly by using the CoreV1 versions of old methods, for example:

kubernetesClient.ListNamespacedPod(@namespace);

became

kubernetesClient.CoreV1.ListNamespacedPod(@namespace);

and

using (Watcher<V1Endpoints> watcher = await kubernetesClient.WatchNamespacedEndpointsAsync(
    this.endpointName,
    this.endpointNamespace,
    onEvent: this.OnEvent,
    onError: this.OnException,
    onClosed: this.OnClose))

became

using (Watcher<V1Endpoints> watcher = kubernetesClient.CoreV1
    .ListNamespacedEndpointsWithHttpMessagesAsync(this.endpointNamespace, fieldSelector: $"metadata.name={this.endpointName}", watch: true)
    .Watch<V1Endpoints, V1EndpointsList>(
        onEvent: this.OnEvent,
        onError: this.OnException,
        onClosed: this.OnClose))

Functionally, it seems to be working.

However, I'm seeing some new Unobserved Exception Errors that look something like this:

System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (The request was aborted.)
 ---> System.IO.IOException: The request was aborted.
   at System.Net.Http.Http2Connection.ThrowRequestAborted(Exception innerException)
   at System.Net.Http.Http2Connection.Http2Stream.CheckResponseBodyState()
   at System.Net.Http.Http2Connection.Http2Stream.TryReadFromBuffer(Span`1 buffer, Boolean partOfSyncRead)
   at System.Net.Http.Http2Connection.Http2Stream.ReadDataAsync(Memory`1 buffer, HttpResponseMessage responseMessage, CancellationToken cancellationToken)
   at k8s.LineSeparatedHttpContent.CancelableStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.IO.StreamReader.ReadBufferAsync(CancellationToken cancellationToken)
   at System.IO.StreamReader.ReadLineAsyncInternal(CancellationToken cancellationToken)
   --- End of inner exception stack trace ---

I'm at a bit of a loss for how to figure out what's causing the issue. Has anyone seen something like this before?

aukevin avatar Sep 05 '25 19:09 aukevin

it looks like your client lost connection to api server or api server kicked the client due to long time inactive (no watch event streaming back)

tg123 avatar Sep 05 '25 19:09 tg123

Thanks! The ThrowRequestAborted does point to a disconnect. But which Task's exception isn't being observed?

aukevin avatar Sep 05 '25 20:09 aukevin

I have a similar issue and I'm not able to track where I'm not awaiting a task. Any wor.

Unobserved Task Exception: True Exception: System.AggregateException Message: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (The request was aborted.) StackTrace: Source: TargetSite: Data: {} Exception: System.IO.IOException Message: The request was aborted. StackTrace: at System.Net.Http.Http2Connection.ThrowRequestAborted(Exception innerException) at System.Net.Http.Http2Connection.Http2Stream.CheckResponseBodyState() at System.Net.Http.Http2Connection.Http2Stream.TryReadFromBuffer(Span1 buffer, Boolean partOfSyncRead) at System.Net.Http.Http2Connection.Http2Stream.ReadDataAsync(Memory1 buffer, HttpResponseMessage responseMessage, CancellationToken cancellationToken) at k8s.LineSeparatedHttpContent.CancelableStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) at System.IO.StreamReader.ReadBufferAsync(CancellationToken cancellationToken) at System.IO.StreamReader.ReadLineAsyncInternal(CancellationToken cancellationToken) Source: System.Net.Http TargetSite: Void ThrowRequestAborted(System.Exception) Data: {}

jschweda avatar Sep 29 '25 15:09 jschweda

could you please shared basic code to repro?

tg123 avatar Oct 01 '25 20:10 tg123