What are the main causes of WebException with the message "Request was aborted: request was canceled."

I am making Http requests using HttpClient. Sometimes I see the following error:

Type of exception: System.Net.WebException
Error message: request was aborted: request was canceled.
in System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult)
in System.Net.Http.HttpClientHandler.GetResponseCallback (IAsyncResult ar)
Exception type: System.Net.Http.HttpRequestException
error message occurred when an error occurred: error message.

I am trying to understand what could be the main reason. There are several posts regarding this post that I can find in StackOverflow (like this post ), but everything seemed to be related to finding workarounds (often things like setting KeepAlive to false which I don't want), where, since I just want to understand what the error really means, I can decide whether and where to act.

+4
source share
1 answer

No one can say for sure.

Enabling network client tracing can help identify the root cause.

Note:

5 , System.Net 6:

s_WebTraceSource = new NclTraceSource("System.Net");
s_HttpListenerTraceSource = new NclTraceSource("System.Net.HttpListener"); // not in the documentation
s_SocketsTraceSource = new NclTraceSource("System.Net.Sockets");
s_WebSocketsTraceSource = new NclTraceSource("System.Net.WebSockets");
s_CacheTraceSource = new NclTraceSource("System.Net.Cache");
s_TraceSourceHttpName = new NclTraceSource("System.Net.Http");

, 5 :

System.Net Verbose: 0 : [9520] WebRequest::Create(http://localhost:9876/)
System.Net Verbose: 0 : [9520] HttpWebRequest#58870012::HttpWebRequest(http://localhost:9876/#363619410)
System.Net Information: 0 : [9520] Current OS installation type is 'Client'.
System.Net Information: 0 : [9520] RAS supported: True
System.Net Verbose: 0 : [9520] Exiting HttpWebRequest#58870012::HttpWebRequest() 
System.Net Verbose: 0 : [9520] Exiting WebRequest::Create()     -> HttpWebRequest#58870012
System.Net Verbose: 0 : [9520] HttpWebRequest#58870012::GetResponse()
System.Net Verbose: 0 : [9520] ServicePoint#33675143::ServicePoint(localhost:9876)
System.Net Information: 0 : [9520] Associating HttpWebRequest#58870012 with ServicePoint#33675143
System.Net Information: 0 : [9520] Associating Connection#34640832 with HttpWebRequest#58870012
System.Net.Sockets Verbose: 0 : [9520] Socket#43332040::Socket(AddressFamily#2)
System.Net.Sockets Verbose: 0 : [9520] Exiting Socket#43332040::Socket() 
System.Net.Sockets Verbose: 0 : [9520] Socket#54444047::Socket(AddressFamily#23)
System.Net.Sockets Verbose: 0 : [9520] Exiting Socket#54444047::Socket() 
System.Net.Sockets Verbose: 0 : [9520] DNS::TryInternalResolve(localhost)
System.Net.Sockets Verbose: 0 : [9520] Socket#43332040::Connect(127.0.0.1:9876#16787179)
System.Net.Sockets Error: 0 : [9520] Socket#43332040::UpdateStatusAfterSocketError() - ConnectionRefused
System.Net.Sockets Error: 0 : [9520] Exception in Socket#43332040::Connect - No connection could be made because the target machine actively refused it 127.0.0.1:9876.
System.Net.Sockets Verbose: 0 : [9520] Socket#43332040::Dispose()
System.Net.Sockets Verbose: 0 : [9520] Socket#54444047::Dispose()
+1

Source: https://habr.com/ru/post/1615594/


All Articles