You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Michael Bell <MJ...@gwava.com> on 2008/11/12 23:52:26 UTC

BindException with NetWork server

Derby 10.4.2.0. Also experienced with earlier.
Java 1.42_16/1.5_16
Windows XP, 2000, 2003. Might also be case on Linux
Tomcat 4.1, 5.5

Situation:

from the System.out (see below)

Could not listen on port 1527 on host localhost:
 java.net.BindException: Address already in use: JVM_Bind

Cause:

Good question. My code is merely

            NetworkServerControl nc = new NetworkServerControl();
            nc.start(new PrintWriter(System.out));

Comments:

This has been a repeated issue. We USUALLY get around it by retrying connections for 30 seconds, but not always

eg the next few lines are

          Class.forName(DERBY_NETWORK_CLIENT_DRIVER);
              } catch (Exception varException)
        {
            log.info(MSG_INIT_FAILURE);
            ErrorHandle.reportError("DerbyStartup", varException);
            throw new IllegalStateException("Cannot proceed without Derby!");
        }
    	Connection con=null;
		try {
			con = DerbyInitializerServlet.getConnectionWithRetry(ascfg); // retry every 500ms for 30 seconds before giving up
		} catch (SQLException e1) {
			log.error("Couldn't get Conn with Retry");
		} finally {
			Parm.close(con);
		
Derby.log:

Apache Derby Network Server - 10.4.2.0 - (689064) started and ready to accept connections on port 1527 at 2008-11-12 22:46:13.328 GMT 
Could not listen on port 1527 on host localhost:
 java.net.BindException: Address already in use: JVM_Bind
An exception was thrown during network server startup. DRDA_ListenPort.S:Could not listen on port 1527 on host localhost:
 java.net.BindException: Address already in use: JVM_Bind
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.apache.derby.iapi.jdbc.DRDAServerStarter.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.Exception: DRDA_ListenPort.S:Could not listen on port 1527 on host localhost:
 java.net.BindException: Address already in use: JVM_Bind
	at org.apache.derby.impl.drda.NetworkServerControlImpl.consolePropertyMessageWork(Unknown Source)
	at org.apache.derby.impl.drda.NetworkServerControlImpl.consolePropertyMessage(Unknown Source)
	at org.apache.derby.impl.drda.NetworkServerControlImpl.blockingStart(Unknown Source)
	... 6 more


What it's not

- not a firewall issue. Firewall is off
- Not true that derby is running, and netstat -a confirms this.




Re: BindException with NetWork server

Posted by Kristian Waagan <Kr...@Sun.COM>.
Hello,

I was asked offline by Michael to post the message below for him.

----- Michael

I figured it out.

          System.setProperty("derby.system.home", ascfg.getEBDBPath() ); 
            System.setProperty(START_NETWORK_SERVER, "true");
            System.out.println("start me");
            NetworkServerControl nc = new NetworkServerControl();
            // change to nc.start(new PrintWriter(System.out)) to see 
            // error messages from server
            
            nc.start(new PrintWriter(System.out));
System.out.println("end start");
if( !ascfg.isInitDone()) Thread.sleep(ARBITRARY_DELAY);
             // and the Client driver for actual access (certainly the connection pool uses this)   
            Class.forName(DERBY_NETWORK_CLIENT_DRIVER);
System.out.println("end instantiate");
            log.info(MSG_INIT_SUCCESS);

This showed the error didn't occur till after this code - until the client driver was instantiated!

The system.setproperty for start_network_server has to be left out, or else the client driver (not the embedded one, or I might have guessed this!) tries to start a second derby.

The system.setproperty was a left over legacy, since the previous program had used that plus the embedded driver to start up Derby. When I refactored to use the "more elegant" NetWorkServerControl, I left the setproperty in, figuring it was harmless. and I figured the client didn't have the same logic as the embedded. Sigh. Live and learn!


Lord know what it is about posting a message about something one has been thinking about for a couple of months that clarifies one's thinking!

-----


-- 
Kristian


Kristian Waagan wrote:
> Michael Bell wrote:
>> Derby 10.4.2.0. Also experienced with earlier.
>> Java 1.42_16/1.5_16
>> Windows XP, 2000, 2003. Might also be case on Linux
>> Tomcat 4.1, 5.5
>>
>> Situation:
>>
>> from the System.out (see below)
>>
>> Could not listen on port 1527 on host localhost:
>>  java.net.BindException: Address already in use: JVM_Bind
>>   
>
> Hello Michael,
>
> Just a few initial questions:
> a) Has Derby been started/restarted earlier when this happens, or does 
> it happen on the first startup attempt?
> b) Have you confirmed that you have nothing else running on port 1527?
> c) From where are you starting the Derby network server?
>    (i.e. standalone app, appserver, embedded in another app)
> d) Does the same thing happen if you start the server with "java -jar 
> derbyrun.jar server start -h 0.0.0.0 -p 1527" (or omit -h if you want 
> to use localhost only)?
> e) Are you using IPv6?
>
> What you describe sure sounds as issues in the socket handling of the 
> OS (or possibly Java) or that something else is using the port, but if 
> it happens the first time you start Derby it might be a bug in Derby 
> itself.
> If you can easily reproduce this, it would be nice if you could run 
> with the debug version.
>
>


Re: BindException with NetWork server

Posted by Kristian Waagan <Kr...@Sun.COM>.
Michael Bell wrote:
> Derby 10.4.2.0. Also experienced with earlier.
> Java 1.42_16/1.5_16
> Windows XP, 2000, 2003. Might also be case on Linux
> Tomcat 4.1, 5.5
>
> Situation:
>
> from the System.out (see below)
>
> Could not listen on port 1527 on host localhost:
>  java.net.BindException: Address already in use: JVM_Bind
>   

Hello Michael,

Just a few initial questions:
 a) Has Derby been started/restarted earlier when this happens, or does 
it happen on the first startup attempt?
 b) Have you confirmed that you have nothing else running on port 1527?
 c) From where are you starting the Derby network server?
    (i.e. standalone app, appserver, embedded in another app)
 d) Does the same thing happen if you start the server with "java -jar 
derbyrun.jar server start -h 0.0.0.0 -p 1527" (or omit -h if you want to 
use localhost only)?
 e) Are you using IPv6?

What you describe sure sounds as issues in the socket handling of the OS 
(or possibly Java) or that something else is using the port, but if it 
happens the first time you start Derby it might be a bug in Derby itself.
If you can easily reproduce this, it would be nice if you could run with 
the debug version.


-- 
Kristian

> Cause:
>
> Good question. My code is merely
>
>             NetworkServerControl nc = new NetworkServerControl();
>             nc.start(new PrintWriter(System.out));
>
> Comments:
>
> This has been a repeated issue. We USUALLY get around it by retrying connections for 30 seconds, but not always
>
> eg the next few lines are
>
>           Class.forName(DERBY_NETWORK_CLIENT_DRIVER);
>               } catch (Exception varException)
>         {
>             log.info(MSG_INIT_FAILURE);
>             ErrorHandle.reportError("DerbyStartup", varException);
>             throw new IllegalStateException("Cannot proceed without Derby!");
>         }
>     	Connection con=null;
> 		try {
> 			con = DerbyInitializerServlet.getConnectionWithRetry(ascfg); // retry every 500ms for 30 seconds before giving up
> 		} catch (SQLException e1) {
> 			log.error("Couldn't get Conn with Retry");
> 		} finally {
> 			Parm.close(con);
> 		
> Derby.log:
>
> Apache Derby Network Server - 10.4.2.0 - (689064) started and ready to accept connections on port 1527 at 2008-11-12 22:46:13.328 GMT 
> Could not listen on port 1527 on host localhost:
>  java.net.BindException: Address already in use: JVM_Bind
> An exception was thrown during network server startup. DRDA_ListenPort.S:Could not listen on port 1527 on host localhost:
>  java.net.BindException: Address already in use: JVM_Bind
> java.lang.reflect.InvocationTargetException
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:585)
> 	at org.apache.derby.iapi.jdbc.DRDAServerStarter.run(Unknown Source)
> 	at java.lang.Thread.run(Thread.java:595)
> Caused by: java.lang.Exception: DRDA_ListenPort.S:Could not listen on port 1527 on host localhost:
>  java.net.BindException: Address already in use: JVM_Bind
> 	at org.apache.derby.impl.drda.NetworkServerControlImpl.consolePropertyMessageWork(Unknown Source)
> 	at org.apache.derby.impl.drda.NetworkServerControlImpl.consolePropertyMessage(Unknown Source)
> 	at org.apache.derby.impl.drda.NetworkServerControlImpl.blockingStart(Unknown Source)
> 	... 6 more
>
>
> What it's not
>
> - not a firewall issue. Firewall is off
> - Not true that derby is running, and netstat -a confirms this.
>
>
>
>