No connection could be made because the target machine actively refused it golang
No connection could be made because the target machine actively refused it golang
target machine actively refused it #845
Comments
lilonghe commented Apr 28, 2019
Problem description
client can not get any response.
error:
rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = \»transport: Error while dialing dial tcp :8091: connectex: No connection could be made because the target machine actively refused it.
but another golang service is ok.
Reproduction steps
Environment
Additional context
The text was updated successfully, but these errors were encountered:
nicolasnoble commented Apr 28, 2019
You didn’t specify in your reproduction case how to install the go dependencies, and I can’t reproduce the full thing because of this, but I can already tell you what’s the issue just looking at the code. In fact, if you only run the node server, you get the following error message:
Specifying :8091 as hostname may be a go-ism, but it’s not generally valid, and you actually need to fully specify the IP:port to which to connect or listen to. Looking at the list of opened ports you can see that your server isn’t actually listening to 8091:
But changing this line:
Makes the startup error go away, and your server will properly start to listen:
How to fix No connection could be made because the target machine actively refused it 127.0.0.1:64527
I have an MVC application which depends on a web API application, I hosted the two on a shared hosting environment. API on the subdomain and MVC on the main domain the API is api.mydomain.com and the MVC is mydomain.com, the API works fine anytime I try it on postman or browser but the MVC cannot connect to it with the following error.
No connection could be made because the target machine actively refused it 127.0.0.1:64527 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:64527
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[SocketException (0x274d): No connection could be made because the target machine actively refused it127.0.0.1:64527]
System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult) +6995036
System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) +84
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +256
[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) +606 System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) +64
[HttpRequestException: An error occurred while sending the request.]
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() +28 SMMClient. d__119 1.MoveNext() in C:\Users\Dload\documents\visual studio 2017\Projects\SMM\SMMClient\Proc.cs:1369
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() +28 SIMSClient.Controllers. d__0.MoveNext() in C:\Users\Dload\documents\visual studio 2017\Projects\SMM\SMMClient\Controllers\HomeController.cs:19
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97
System.Web.Mvc.Async.<>c__DisplayClass37. b__36(IAsyncResult asyncResult) +17
System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.AsyncInvocationWithFilters. b__3d() +50 System.Web.Mvc.Async.<>c__DisplayClass46. b__3f() +228 System.Web.Mvc.Async.<>c__DisplayClass33. b__32(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass2b. b__1c() +26 System.Web.Mvc.Async.<>c__DisplayClass21. b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +48
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller. b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +48
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +38 System.Web.Mvc.Controller. b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +48
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +28
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler. b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +48
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.InvokeEndHandler(IAsyncResult ar) +152 System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +125
This is how I connect to the API from Global.asax.cs
This is how I call a resource
I’m able to connect to the live API from my local MVC application but I can not connect to the API from live MVC application.
No connection could be made because the target machine actively refused it 127.0.0.1:3446
The problem always occur at
Class for streaming:
Windows Form project: for testing
I’ve turned off the firewall and my Internet connection, but the error still exists. Is there a better way of testing the uploading method?
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
19 Answers 19
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
«Actively refused it» means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port. This may be because it is not running at all or because it is listening on a different port.
You don’t have to restart the PC. Restart IIS instead.
I got a similar error message like TCP error code 10061: No connection could be made because the target machine actively refused it in my current project. I find this 10061 error code cannot distinguish the case that the service endpoint is not started and the case that it is blocked by the firewall. Often, the firewall can be switched off, but the problem is still there.
You can test your code in the below two ways.
Above is my fix. It works on my machine. I hope it helps!
Postgresql: No connection could be made because the target machine actively refused it
Running Postgresql 9.5 on a windows server 2012 R2 in Azure
While running some loadtests on my application, I get errors on not being able to connect to the postgres server. In the logs of postgres I get the following message:
could not receive data from client: No connection could be made because the target machine actively refused it.
This only happens when the loadtest goes to the next scenario, hitting a different part of the code. So new connections to the database are required. But after 10-20 seconds the rest of the scenario works flawlessly without hitting any other hiccups. So the problem seems to be the tcp connections. (My code retries a couple of times but it is not feasible to let it retry for 20 seconds)
I’m using the following settings in the config files
I know, I know.. It is not save to accept connections from everyone, but this is just for testing purposes and to make sure these settings are not blocking any connection. So this answer is void
I’ve been monitoring the number of connection on the server and under the load it is stable at 75. Postgres is using around 350mb of RAM. So given the config and the vm specs (7gb ram) there should be plenty of space to create more connections. However when the next scenario is spinning up the number of connections does not increase, it stays level and starts giving these log messages about no connection could be made.
No connection could be made because the target machine actively refused it 127.0.0.1:port with subdomain
I am running an ASP.NET MVC 5 application which also hosts IdentityServer3. As many others have experienced before, when I connect to this endpoint.
. I get the following error:
No connection could be made because the target machine actively refused it 127.0.0.1:51515 at System.Net.HttpWebRequest.GetResponse() at RestSharp.Http.GetRawResponse(HttpWebRequest request) at RestSharp.Http.GetResponse(HttpWebRequest request)
C# (using RestSharp):
I made a few alternatives for these samples, for instance by including a host header (value tenant1.localhost:51515) or using that same uri as the proxy for the web clients. Unfortunately they all return the same error.
Strangely enough all of the requests I make with my browser or Postman succeed. JavaScript code that connects to the endpoints also works. There’s one exception to this: as soon as as I have a Fiddler session running, this is the response I get from Postman:
[Fiddler] The connection to ‘tenant1.localhost’ failed.
Error: ConnectionRefused (0x274d).
System.Net.Sockets.SocketException No connection could be made because the target machine actively refused it 127.0.0.1:51515
I have been looking for a solution for days now but I can’t seem to find the right one but it seems clear that only in server side code the problem occurs. Here’s what I have tried so far. I included the applicationhost.config and hosts file to show how I ‘enabled’ subdomains for my web application (which are internally used to identify the tenants). Furthermore I use IIS Express for local development and IIS for production environments.
Applicationhost.config
Hosts file
Netstat
I am not sure what these values mean so I could use some input here. Just to make sure I disconnected from the Internet and disabled both firewall and anti virus scanners, with no result.
Proxy
These are my Internet Options settings. As you see, everything is checked out:
I tried all sorts of combinations with the proxy settings in my web/app.config files. I don’t think this will play a major role in resolving the issue as I have the same problems with my Golang app (which is merely a code snippet generated by Postman). I even tried to use Fiddler as the proxy by setting the url to http://127.0.0.1:8888. As to be expected, any server side proxies for the WebRequest instances didn’t help either.
Visual Studio
Question
Given the numerous questions about this topic the only remarkable difference I see is that I use a subdomain in my url. Whenever I don’t use a subdomain everything works perfectly!
If this assumption appears to be correct, how can I trick the DNS, firewall or any other blocking mechanism to accept requests from the subdomain(s)? Maybe a proxy could help?
Источники информации:
- http://stackoverflow.com/questions/55600630/how-to-fix-no-connection-could-be-made-because-the-target-machine-actively-refus
- http://stackoverflow.com/questions/9695224/no-connection-could-be-made-because-the-target-machine-actively-refused-it-127-0
- http://stackoverflow.com/questions/38730065/postgresql-no-connection-could-be-made-because-the-target-machine-actively-refu
- http://stackoverflow.com/questions/45154536/no-connection-could-be-made-because-the-target-machine-actively-refused-it-127-0