Bug 66822

Summary: "BindException: Address already in use" - pls say which ip/port is causing the problem
Product: Tomcat 9 Reporter: Ralf Hauser <hauser>
Component: ConnectorsAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: enhancement CC: contact
Priority: P2    
Version: 9.0.43   
Target Milestone: -----   
Hardware: Other   
OS: Linux   

Description Ralf Hauser 2023-07-31 10:08:19 UTC
if the mnemonic DNS name is know best mention that one too

Caused by: java.net.BindException: Address already in use
		at java.base/sun.nio.ch.Net.bind0(Native Method)
		at java.base/sun.nio.ch.Net.bind(Net.java:555)
		at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337)
		at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294)
		at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:277)


similar to bug 47499 , Bug 44558
Comment 1 Mark Thomas 2023-07-31 12:54:55 UTC
The IP/port information is already in the log file. The log line before the quoted  exception provides the protocol (AJP, HTTP, etc) , Connector (NIO, NIO2, etc), Address (if any) and port.
Comment 2 Graham Leggett 2023-07-31 13:02:30 UTC
+1 to fixing the error message.

There is no obvious link between log lines on different lines, just because a port appears on previous line, it means nothing.

Please fix this.
Comment 3 Antonio Ancona 2023-07-31 13:45:41 UTC
Similar undescriptive error case in the same class:

31-Jul-2023 13:38:12.493 SEVERE [main] org.apache.catalina.util.LifecycleBase.handleSubClassException Failed to initialize component [Connector[HTTP/1.1-8443]]
	org.apache.catalina.LifecycleException: Protocol handler initialization failed
		at org.apache.catalina.connector.Connector.initInternal(Connector.java:1049)
		at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
		at org.apache.catalina.core.StandardService.initInternal(StandardService.java:558)
		at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
		at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:1045)
		at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
		at org.apache.catalina.startup.Catalina.load(Catalina.java:724)
		at org.apache.catalina.startup.Catalina.load(Catalina.java:746)
		at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
		at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
		at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
		at java.base/java.lang.reflect.Method.invoke(Method.java:568)
		at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:302)
		at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:472)
	Caused by: java.net.BindException: Cannot assign requested address
		at java.base/sun.nio.ch.Net.bind0(Native Method)
		at java.base/sun.nio.ch.Net.bind(Net.java:555)
		at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337)
		at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294)
		at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:277)
		at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:241)
		at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1193)
		at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:1206)
		at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:597)
		at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:80)
		at org.apache.catalina.connector.Connector.initInternal(Connector.java:1046)
		... 13 more
Comment 4 Antonio Ancona 2023-07-31 15:13:02 UTC
We have multiple connectors listening on port 8443 in our server.xml, each of them with a different "address" field.

As Ralf Hauser suggested, it would be beneficial to cite this address verbatimely, the corresponding IP address.
In case the address field is an IP address to begin with, the reverse DNS lookup  would be very helpful.
If this all could be cited in "[Connector[HTTP/1.1-8443]]" (and in the exception message as soon as "NioEndpoint" gets hold of it (java.net.BindException: Address already in use).
Comment 5 Ralf Hauser 2023-07-31 15:29:50 UTC
also, it would be useful to be clearer on the protocol:

The current error message says "HTTP/1.1".

In reality it is most likely "https" as the connector has the attributes

scheme="https"
secure="true" 
SSLEnabled="true"
...
keystoreFile="/usr/share/tomcat9/conf/sec/.keystore"
keystorePass="*****"
certificateKeystoreType="PKCS12"
...
sslProtocol="TLSv1.2"
sslEnabledProtocols="TLSv1.2+TLSv1.3"
useServerCipherSuitesOrder="true"
ciphers="TLS_AE...
Comment 6 Mark Thomas 2023-08-03 13:46:02 UTC
Connector log messages now use the same name format as the protocol handler (e.g. "http-nio-127.0.0.1-8080") to reference the Connector.

Fixed in:
- 11.0.x for 11.0.0-10 onwards
- 10.1.x for 10.1.12 onwards
-  9.0.x for  9.0.79 onwards
-  8.5.x for  8.5.92 onwards