Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to read data from the transport connection: Operation canceled

We have a .NET WorkerService that is running in the background pending trigger from the Event Hubs to push data to an API webservice but we are running into this issue:

Any ideas what could be causing this ?

​​​​ExceptionSource: "System.Net.Http", ExceptionType: "System.Threading.Tasks.TaskCanceledException: The operation was canceled. 

System.IO.IOException: Unable to read data from the transport connection: Operation canceled.

System.Net.Sockets.SocketException (125): Operation canceled 

End of inner exception stack trace --- 
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) 
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token) 
at System.Net.Security.SslStream.<FillBufferAsync>g__InternalFillBufferAsync|215_0[TReadAdapter](TReadAdapter adap, ValueTask`1 task, Int32 min, Int32 initial) 
at System.Net.Security.SslStream.ReadAsyncInternal[TReadAdapter](TReadAdapter adapter, Memory`1 buffer) 
at System.Net.Http.HttpConnection.FillAsync() 
at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed) 
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) 

--- End of inner exception stack trace --- 
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) 
at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) 
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) 
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) 
at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) 
at Client.MyClient.UpdateAsync(DataRequestUpdate DataRequest, CancellationToken cancellationToken) in /src/Client/Client.cs:line 1232 
at Client.Repository.Update(Request data) in /src/Client/Repository.cs:line 32 
at WorkerService.EventProcessor.Update(UpdateRequest request) in /src/WorkerService/EventProcessor.cs:line 390", Message: "The operation was canceled." }​
like image 245
chad Avatar asked Jan 25 '26 07:01

chad


1 Answers

The default .NET httpclient timeout is 100 secs. If your client takes more than 100 secs, it will result in the above error. To solve this, simply increase the timeout value.

HttpClient httpClient = new HttpClient(); 
httpClient.Timeout = TimeSpan.FromMinutes(10); //Eg. 10mins timeout 
like image 168
chad Avatar answered Jan 27 '26 22:01

chad