db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brett Wooldridge (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-3108) Iteratively creating and closing client connection yields java.net.BindException: Address already in use: connect after many connections
Date Thu, 08 Nov 2012 06:50:14 GMT

    [ https://issues.apache.org/jira/browse/DERBY-3108?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13493004#comment-13493004
] 

Brett Wooldridge commented on DERBY-3108:
-----------------------------------------

Probably of equal or greater important is the same on the NetworkServer side of the equation:

Index: java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
===================================================================
--- java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java	(revision 1406929)
+++ java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java	(working copy)
@@ -31,6 +31,7 @@
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import javax.net.SocketFactory;
@@ -667,28 +668,35 @@
 											
 		// Create the right kind of socket
 		switch (getSSLMode()) {
-		case SSL_OFF:
-		default:
-			ServerSocketFactory sf =
-				ServerSocketFactory.getDefault();
-			return sf.createServerSocket(portNumber
-										 ,0,
-										 hostAddress);
-		case SSL_BASIC:
-			SSLServerSocketFactory ssf =
-				(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
-			return (SSLServerSocket)ssf.createServerSocket(portNumber,
-														   0,
-														   hostAddress);
-		case SSL_PEER_AUTHENTICATION:
-			SSLServerSocketFactory ssf2 =
-				(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
-			SSLServerSocket sss2= 
-				(SSLServerSocket)ssf2.createServerSocket(portNumber,
-														 0,
-														 hostAddress);
-			sss2.setNeedClientAuth(true);
-			return sss2;
+			case SSL_OFF:
+			default:
+			{
+				ServerSocketFactory sf = ServerSocketFactory.getDefault();
+				ServerSocket socket = sf.createServerSocket();
+				socket.setReuseAddress(true);
+				socket.bind(new InetSocketAddress(hostAddress, portNumber));
+				return socket;
+			}
+			case SSL_BASIC:
+			{
+				SSLServerSocketFactory ssf =
+						(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
+				ServerSocket socket = (SSLServerSocket)ssf.createServerSocket();
+				socket.setReuseAddress(true);
+				socket.bind(new InetSocketAddress(hostAddress, portNumber));
+				return socket;
+			}
+			case SSL_PEER_AUTHENTICATION:
+			{
+				SSLServerSocketFactory ssf2 =
+						(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
+				SSLServerSocket sss2= 
+						(SSLServerSocket)ssf2.createServerSocket();
+				sss2.setReuseAddress(true);
+				sss2.setNeedClientAuth(true);
+				sss2.bind(new InetSocketAddress(hostAddress, portNumber));
+				return sss2;
+			}
 		}
 	}
 	
With this change, the server should never fail a bind due to sockets in the TIME_WAIT state.
 The only time a bind() would fail in this case is if there are truly no more ephemeral ports
available (i.e. > 65000 connection).

                
> Iteratively creating and closing client connection yields java.net.BindException: Address
already in use: connect after many connections
> ----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-3108
>                 URL: https://issues.apache.org/jira/browse/DERBY-3108
>             Project: Derby
>          Issue Type: Bug
>          Components: Network Client, Network Server
>    Affects Versions: 10.4.1.3
>            Reporter: Kathey Marsden
>         Attachments: ConnLoop.java
>
>
> The attached program ConnLoop just creates client connections, uses them and then closes
them. After about 3000 connections I get the following error.  Also the memory usage seems
to be increasing rapidly.  This may be the cause of DERBY-2344.
> [C:/kmarsden/repro/DERBY-2344] java ConnLoop
> Apache Derby Network Server - 10.4.0.0 alpha - (578868M) started and ready to accept
connections on port 1527 at 2007-10
> -05 15:56:57.500 GMT
> 0:total memory: 5435392 free: 2749776 Fri Oct 05 08:57:09 PDT 2007
> 1000:total memory: 13701120 free: 10586720 Fri Oct 05 08:57:40 PDT 2007
> 2000:total memory: 20738048 free: 12805336 Fri Oct 05 08:58:09 PDT 2007
> 3000:total memory: 24006656 free: 11053832 Fri Oct 05 08:58:40 PDT 2007
> Exception in thread "main" java.sql.SQLNonTransientConnectionException: java.net.BindException
: Error connecting to ser
> ver localhost on port 1527 with message Address already in use: connect.
>         at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:70)
>         at org.apache.derby.client.am.SqlException.getSQLException(SqlException.java:362)
>         at org.apache.derby.jdbc.ClientDriver.connect(ClientDriver.java:149)
>         at java.sql.DriverManager.getConnection(DriverManager.java:582)
>         at java.sql.DriverManager.getConnection(DriverManager.java:207)
>         at ConnLoop.main(ConnLoop.java:18)
> Caused by: org.apache.derby.client.am.DisconnectException: java.net.BindException : Error
connecting to server localhost
>  on port 1527 with message Address already in use: connect.
>         at org.apache.derby.client.net.NetAgent.<init>(NetAgent.java:129)
>         at org.apache.derby.client.net.NetConnection.newAgent_(NetConnection.java:1086)
>         at org.apache.derby.client.am.Connection.<init>(Connection.java:349)
>         at org.apache.derby.client.net.NetConnection.<init>(NetConnection.java:209)
>         at org.apache.derby.client.net.NetConnection40.<init>(NetConnection40.java:77)
>         at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(ClientJDBCObjectFactoryImpl40.java
> :209)
>         at org.apache.derby.jdbc.ClientDriver.connect(ClientDriver.java:140)
>         ... 3 more
> Caused by: java.net.BindException: Address already in use: connect
>         at java.net.PlainSocketImpl.socketConnect(Native Method)
>         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
>         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
>         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
>         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
>         at java.net.Socket.connect(Socket.java:519)
>         at java.net.Socket.connect(Socket.java:469)
>         at java.net.Socket.<init>(Socket.java:366)
>         at java.net.Socket.<init>(Socket.java:179)
>         at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:196)
>         at org.apache.derby.client.net.OpenSocketAction.run(OpenSocketAction.java:62)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at org.apache.derby.client.net.NetAgent.<init>(NetAgent.java:127)
>         ... 9 more
> [C:/kmarsden/repro/DERBY-2344]

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message