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." }​

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x