Solving java.net.BindException: Address already in use: JVM_Bind

solving javanetbindexception address already in use jvmbind 107816

When dealing with Java applications, the “java.Net.BindException: Address already in use: JVM_Bind” error can often pose a common obstacle. It serves as a clear indicator that a different process is currently utilizing the network address and port, thereby hindering the binding process for your application. Fear not, for in this tutorial, we shall embark upon a journey of discovering ingenious remedies to conquer this error and ensure seamless operation for your Java application.

When attempting to initialize JBoss or WildFly, the error “java.Net.BindException: Address already in use: JVM_Bind” may arise, indicating that the specified address is already being utilized. This issue is not exclusive to any specific Java service, but rather a common occurrence in such scenarios.

java.net.BindException: Address already in use

It’s highly probable that there is still a lingering JBoss instance running, possibly due to an abrupt termination. The “jps” utility, found in every Java distribution, swiftly reveals all active Java processes.

$ jps
104503 Jps
102474 jboss-modules.jar

Observe, there exists a solitary Java process that utilizes the resource “jboss-modules.Jar”. The application server establishes connections with various network ports, contingent upon the specific JBoss / WildFly profile in operation.

Take, as an illustration, the utilization of the following bindings in an HA Profile:


        
        
        
        
        
        
        
        
        
        
        
        
        
        
            
        

However, it is worth mentioning that the primary reason behind this issue is often attributed to another WildFly server actively occupying either the HTTP port (8080) or the management port (9990).

In the event of an improper shutdown causing the occurrence of this WildFly process, you have the option to cease it effortlessly using an OS command like ‘kill -9’. As an illustration, to terminate the aforementioned process with ID 102474:.

kill -9 102474

Conversely, should your application server necessitate harmonizing with the preexisting WildFly server, you have the option to initiate it with a port deviation, through configuring the jboss.Socket.Binding.Port-offset property.

See also  What happens if you leave Trees floating in Minecraft?

For example:.

./standalone.sh -Djboss.socket.binding.port-offset=100

To configure the Port Offset in Domain mode, it is advisable to make use of the Management Interfaces. To gain a deeper understanding of this process, we suggest referring to the following article: A Comprehensive Guide on Configuring WildFly in Domain mode.

Addressing the JVM_Bind Error

In case a different WildFly server is not obstructing the port, it becomes imperative to identify the responsible process. Numerous command line utilities are available for both Unix and Windows operating systems that can assist in accomplishing this task.

Unix users:.

Discovering PID-Process Name details for a specific user is a breeze in the majority of Linux distributions using the subsequent command.

$ netstat -tulpn | grep 8080 
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 22005/java

Fuser, yet another mighty weapon in the arsenal, possesses the ability to scrutinize the processes that employ TCP/UDP sockets. Let’s delve into the art of unveiling the process that embraces a TCP Socket on the majestic port 8080:

$ fuser -v -n tcp 8080

Windows users:.

Utilizing netstat grants access to comprehensive network data for every process. In the subsequent illustration, we apply a meticulous filter on port 8080.

netstat -ano | find "8080"

Input: By utilizing your PID as 1234, you can effectively identify the active process occupying your Port and proceed to terminate it with the following execution:

taskkill -pid 1234 /f

In addition to terminating your process, the TaskManager offers the option to put an end to it. It’s worth noting that the PID is not displayed by the Task Manager by default. To view the PID, you need to navigate to the menu and select columns under the View section.

See also  How to Make a Pickaxe in Minecraft?

If you happen to be utilizing outdated versions of JBoss, it’s quite likely that MS Office or MS OfficeCommunicator are actively occupying ports 1098 and 1099. If you prefer not to close these applications, your sole alternative is to employ an alternative binding address.

Mac Users:.

Discover the unique process identifier by executing it directly from the Terminal.

lsof -i:

Terminate the procedure using:.

kill 

Allow sufficient time for resource release

In this particular scenario, the previous process tends to take its time in shutting down entirely. To tackle this, you have the option to incorporate a delay or retry mechanism when initializing the application, thus granting the previous process sufficient time to relinquish control over the address and port.

There are instances where you might desire to tweak the duration of the TIME_WAIT state. Make alterations to the TCP/IP configurations on your operating system in order to shorten the duration of the TIME_WAIT state. This enables the address and port to swiftly become available for reuse.

Run the given command to check the current value of the net.Ipv4.Tcp_tw_reuse parameter on a Linux machine.

sysctl net.ipv4.tcp_tw_reuse
  • If the value is already set to 1, it signifies that the reusability of TCP connections in TIME_WAIT state is enabled. Consequently, no additional modifications might be necessary.
  • Modify the value to 0 to signify that the reuse of TCP connections in the TIME_WAIT state is not taking place. Alter this by executing the subsequent command:
  • sudo sysctl -w net.ipv4.tcp_tw_reuse=1
    

    java.net.BindException: Cannot assign requested address:

    It is highly likely that you are using an incorrect address for one of the network interfaces configured in the application server, indicating the need for correction. Upon booting the application server and assigning a hostname, this issue can be resolved.

    $ ./standalone.sh -b hostname

    In both Windows and Linux operating systems, the file /etc/host serves the purpose of converting domain names into corresponding IP addresses. However, if this translation is flawed, you may encounter the java.Net.BindException: Cannot assign requested address: JVM_Bind error.

    Conclusion.

    By embracing the solutions and techniques elucidated in this tutorial, you can proficiently conquer the “java.Net.BindException: Address already in use: JVM_Bind” error. Grasping the origins, pinpointing the clashing process, and implementing apt remedies will guarantee seamless and uninterrupted execution of your Java applications. Don’t forget to routinely monitor and optimize the utilization of your application’s network resources to avert the reoccurrence of this error.

    Don’t forget to check out this fantastic tutorial that delves deeper into the world of JBoss port configuration.

    Leave a Reply

    Your email address will not be published. Required fields are marked *