Java.net.SocketException:No buffer space available (maximum connections reached?): Connect problem analysis __.net

Source: Internet
Author: User
Exception Log
 caused By:java.net.SocketException:No buffer space available (maximum connections reached?): Connect at Java.net.Tw Ostacksplainsocketimpl.socketconnect (Native method) at Java.net.AbstractPlainSocketImpl.doConnect ( abstractplainsocketimpl.java:350) at Java.net.AbstractPlainSocketImpl.connectToAddress ( abstractplainsocketimpl.java:206) at Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:188) A T Java.net.PlainSocketImpl.connect (plainsocketimpl.java:172) at Java.net.SocksSocketImpl.connect ( sockssocketimpl.java:392) at Java.net.Socket.connect (socket.java:589) at Org.apache.http.conn.scheme.PlainSocketFa Ctory.connectsocket (plainsocketfactory.java:121) at Org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection (Defaultclientconnectionoperator.java : 180) at Org.apache.http.impl.conn.ManagedClientConnectionImpl.open (managedclientconnectionimpl.java:326) at ORG.A Pache.http.impl.client.DefaultRequestDirector.tryConneCT (defaultrequestdirector.java:610) at Org.apache.http.impl.client.DefaultRequestDirector.execute ( defaultrequestdirector.java:445) at Org.apache.http.impl.client.AbstractHttpClient.doExecute ( abstracthttpclient.java:835) at Org.apache.http.impl.client.CloseableHttpClient.execute (Closeablehttpclient.java : Org.apache.http.impl.client.CloseableHttpClient.execute at ORG.APACHE.HTTP.I (closeablehttpclient.java:108)
 Mpl.client.CloseableHttpClient.execute (closeablehttpclient.java:56)

Problem Analysis
Online said no buffer space available (maximum connections reached?) Because the machine port number is exhausted, TCP cannot request a new port to establish a connection. First think of to see the machine port number usage.

A large number of ports in the TIME_WAIT state, the initial estimate may be the client every time to request the server to create a TCP connection, the end of the connection, but the TCP protocol if the client actively shut down, in order to ensure that the message sent does not affect the next connection, the active shutdown needs to stay _wait State 2*MSL (Max Segment Lifetime). When the concurrent high, will produce a large number of time_wait, and in the TIME_WAIT state of the port is not immediately to establish a new connection, which leads to no buffer space available (maximum connections reached?) This exception.

Problem fixes
The troubleshooting code found that there was a rest request that created one httpclient at a time. It is equivalent to re-establish the TCP connection each time, complete 3 handshake and 4 wave.

The repaired code uses an HTTP connection pool to take a duplicate HTTP connection. This eliminates the need to create a new TCP connection every time. Not only can you avoid the port being filled up, you can also improve IO performance (TCP connection setup and shutdown are overhead). HttpClient provides Poolinghttpclientconnectionmanager classes to support the management of HTTP connection pools.

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.