Operation was attempted on a nonexistent network connection error - c#

In my C# SignalR project, Facing the internal socket error during the hubconnection dispose and sometimes the code wont run, showing the exception provided below and also after the first execution , will be running fine for sometime. Is there anything that need to be done along with the hubconnection disposal or how the hubconnection disposal can be achieved properly so that this problem won't be recurring?
System.AggregateException: One or more errors occurred.
System.Net.Http.HttpRequestException: An error occurred while sending the request.
System.Net.WebException: Unable to connect to the remote server
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it.
Stack Trace:
Socket.InternalEndConnect(IAsyncResult asyncResult)
Socket.EndConnect(IAsyncResult asyncResult)
ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
HttpClientHandler.GetResponseCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
Task.Wait()

Related

SignalR connection issue with a server

So I recently bought a vps to try SignalR in my project, I used this example : Simple SignalR Project
Unfortunately though I do not have any experience with such things, I uploaded the ServerSide program on my vps and tried to connect with it, but I get the following error : An error occurred while sending the request.
More Detailed :
System.Net.Http.HttpRequestException' in mscorlib.dll
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ip:9080
at System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult)
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) / System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ip:9080
at System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult)
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
So I was wondering if I'm doing anything wrong here, or need to do any specific settings/setups on my server
by the way my goal is to have a connection with a server and get real-time data for my project, so if there's any better alternatives, would appreciate suggestions
well, found the solution, my firewall was preventing the connection

Azure functions throws "An error occurred while sending the request" for some of my customers

All Azure functions work fine in "MySoftware 2.0.14". I had to redeploy all azure functions and change the addresses in the software and release the new version "MySoftware 2.0.18". Everything worked good but for about 3-10% of my customers stopped working all functions.
I had a TeamViewer session with a lot of these guys and the functions behave like they just don't exist. Like when I change the function address to some random string. It is in both cases throws "An error occurred while sending the request."
The full exception of these guys:
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
--- End of inner exception stack trace ---
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at (TaskAwaiter`1& )
at InstaGTO.Model.ServerCommunication.ServerRequest.♶┩♼﵆⚝┚⚶╇╽♅⚢▚♋﷜⛴﷖╬♽⛣⚒⚧﷈⛍▄￱☽▄┢﷪┒▷◔┪╨⚿﷟♻䷪♩☈☯╃䷃╓⚨⚾♠◪▒☦☔┻╩﷾⛿﵏┅╰䷚▊┸◞䷠￸⛂◑♑┾╲◟⚇♞╇┈﯃◢﷚╳│⛖☃☲┼◩▼◢﵅◨█┕﷮╄⚞┨◤◊⛣┦.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at (TaskAwaiter`1& )
at InstaGTO.ViewModel.RegistrationViewModel.◮☶╞☿﷧┿䷯⚥╻╋﮻♭┣▣╖⚇☢﯀☼￳☝♐﯃⛔⚇﷎☗⛤☣﵂䷤䷦◥╱▩⛃╷⚒﷑▉⚫▇⚓⚺◻▒♓╥䷹║♀●═╺䷚䷵䷲﯈䷾﷬┞☍♶⛎﷡◜▚♥◕♒┉☬▌▀⚻䷜☸◿▫﷚◶⚀├▹⛼╢┤⛤╄⚚♔⛲◱♬╲★￴◷┸.MoveNext()
I didn't make any changes in the functions neither in the code. I just only deploy them on the new Azure plan and change addresses in the software. I really don't understand why it doesn't work for someone. The insights didn't notice any error but my software just doesn't work for those guys because they cannot sign up, cannot request a new password, register and all stuff on the cloud.
As suggested by Hari, Following https://github.com/Azure/azure-functions-host/issues/3665 and SSL changed to 1.0 did solve the issue.

Selenium WebDriver Socket Exception

Everything was working fine till yesterday and from today onward , I have started facing the issue intermittently at any stage but frequently
{"Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted 127.0.0.1:21235\r\n at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)\r\n at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)\r\n --- End of inner exception stack trace ---\r\n at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)\r\n at System.Net.HttpWebRequest.GetRequestStream()\r\n at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)\r\n at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)\r\n at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)\r\n at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)"}
I have already tried basic stuffs, like see if port is not in use already or bind to someone, but that doesn't seem to be the issue.
Not sure, what's wrong, anybody else has any idea or have faced something similar then please help me out here
Thanks in Advance

.NET HttpClient - An existing connection was forcibly closed by the remote host

I have this code called from an ASP.NET MVC controller:
protected string PostData(string url, ByteArrayContent content)
{
using (var client = new HttpClient())
{
client.Timeout = TimeSpan.FromDays(1);
return client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
}
}
If I am posting data to a REST service which takes some time to execute, I get this error:
System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
at System.Net.PooledStream.EndRead(IAsyncResult asyncResult)
at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at Libcor.Services.Ssp.External.ExternalServiceBase.PostData(String absoluteUrl, ByteArrayContent content)
The REST service still completes it's work in the background but the ASP.NET MVC gets this exception. Works fine for shorter running services. How do I prevent this from happening?
Adding this helped:
_client.DefaultRequestHeaders.Add("Connection", "Keep-Alive");
_client.DefaultRequestHeaders.Add("Keep-Alive", "3600");
I managed to keep the request alive long enough for it to complete gracefully and receive a valid response.
The solution for me was updating the https protocol from the default ssl3 to tls via https://stackoverflow.com/a/46223433/352432
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

WebException: Unable to connect to the remote server

I have a client application that uses WebHttpRequest to get response from external server, it works fine but some times I'm getting the following exception ....
System.Net.WebException: Unable to
connect to the remote server --->
System.Net.Sockets.SocketException: A
connection attempt failed because the
connected party did not properly
respond after a period of time, or
established connection failed because
connected host has failed to respond
xx.xx.xxx.xxx:xxx at
System.Net.Sockets.Socket.DoConnect(EndPoint
endPointSnapshot, SocketAddress
socketAddress) at
System.Net.Sockets.Socket.InternalConnect(EndPoint
remoteEP) at
System.Net.ServicePoint.ConnectSocketInternal(Boolean
connectFailure, Socket s4, Socket s6,
Socket& socket, IPAddress& address,
ConnectSocketState state, IAsyncResult
asyncResult, Int32 timeout, Exception&
exception) --- End of inner
exception stack trace ---
at
System.Net.HttpWebRequest.GetRequestStream(TransportContext&
context)
at
System.Net.HttpWebRequest.GetRequestStream()
.... Any help?
This is more of a "Request Timed Out" error. The server you are trying to connect to did not respond to your request. You should handle this exception using try-catch and attempt to connect n number of times again in the catch block.

Categories