For exception handling that is actively rejected by the target in the case of high concurrency, the WCF Exception Handling

Source: Internet
Author: User

For exception handling that is actively rejected by the target in the case of high concurrency, the WCF Exception Handling

Recently, I got a wcf Monitoring Service. Occasionally, when the target service is monitored, an error is reported that the target is actively rejected. At first, I thought the service was stopped and I checked the target service on the server. So I started to check the cause.

Generally, the exceptions of the target positive rejection (TCP 10061) are mainly two possibilities:

1: server shutdown or service Shutdown

2: The Client calls a port error or the server firewall does not open the corresponding port.

However, our service itself can be called, but this error is occasionally reported, indicating that it is not caused by these two problems. Continue to google and see this article on stackoverflow: Portal

If this happens always, it literally means that the machine exists but that it has no services listening on the specified port, or there is a firewall stopping you.If it happens occasionally - you used the word "sometimes" - and retrying succeeds, it is likely because the server has a full 'backlog'.When you are waiting to be accepted on a listening socket, you are placed in a backlog. This backlog is finite and quite short - values of 1, 2 or 3 are not unusual - and so the OS might be unable to queue your request for the 'accept' to consume.The backlog is a parameter on the listen function - all languages and platforms have basically the same API in this regard, even the C# one. This parameter is often configurable if you control the server, and is likely read from some settings file or the registry. Investigate how to configure your server.If you wrote the server, you might have heavy processing in the accept of your socket, and this can be better moved to a separate worker-thread so your accept is always ready to receive connections. There are various architecture choices you can explore that mitigate queuing up clients and processing them sequentially.Regardless of whether you can increase the server backlog, you do need retry logic in your client code to cope with this issue - as even with a long backlog the server might be receiving lots of other requests on that port at that time.There is a rare possibility where a NAT router would give this error should it's ports for mappings be exhausted. I think we can discard this possibility as too much of a long shot though, since the router has 64K simultaneous connections to the same destination address/port before exhaustion.

It probably means that if this error occurs all the time, it may be a server or firewall problem. If this problem occurs in "Sometime", it may be a backlog problem. Backlog is a tcp Request queue. When you call a socket to initiate a request, the server will be in a queue. In high concurrency, the server cannot process the request, so some requests will be directly discarded, therefore, the exception of the target actively rejecting TCP10061 was reported.

With backlog, I continued to google the keyword "WCF backlog" and found that the wcf binding configuration does have a listenBacklog project. The default value is 10. So I changed the listenBacklog of the Service to 100, and the problem was solved.

When adding the listenBacklog attribute, you must remove a default endpoint <endpoint address = "mex" binding = "mexTcpBinding" bindingConfiguration = "" contract = "IMetadataExchange "/> this endpoint is used to discover metadata such as, if you do not remove the listener, an error will be reported.

Refer:

Http://stackoverflow.com/questions/2972600/no-connection-could-be-made-because-the-target-machine-actively-refused-it

Https://msdn.microsoft.com/en-us/library/ee377061 (v = bts.10). aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.