Failed To Set up Listener: SocketException: Address Already in Use

Failed To Set Up Listener: Socketexception: Address Already In Use

Failed to set up listener: SocketException: Address already in use would possibly seem if you attempt to run a brand new MongoDB occasion over an current one or its stays. In different phrases, this exception is the noise made by a busy port.Failed To Set Up Listener Socketexception Address Already In Use

No worries when you don’t know the right way to cope with such a state of affairs as a result of this put up will say all of it. By the tip of this masterpiece, you’ll have recognized the issue and mastered the options.

SocketException: Address Already in Use: Two Major Causes

The MongoDB socket exception connection refused comes up on account of two causes. The first and most typical trigger is an current mongod occasion, whereas the second trigger is the .sock file of a earlier occasion. So, even when you haven’t left an occasion working, the .sock file can create points.

– A Mongod Instance Is Already Running

If your mongod occasion is already working, the listener socketexception handle error will seem in your display screen. It is as a result of working a mongod occasion will occupy the port, and a busy port can’t run one other mongod occasion. Thus, the issue is your present mongod occasion.

Try imagining a state of affairs in which you had been working the MongoDB server. You didn’t cease the method and forgot about it. Now, you are attempting to begin the server once more. In this state of affairs, the acknowledged error will interrupt the mongod command execution.

– The .sock File Sitting on Your System

Although the .sock file isn’t dangerous to maintain in your PC, it should be deleted with the termination of the method that creates it. If it sits in your system after the method termination, an error setting up listener MongoDB will happen.Socketexception Address Already In Use Causes

In case you don’t know, the .sock file is used for communication between the processes, this system, and the server. It is created by a course of when it’s initiated. Once you terminate a course of, the .sock file is deleted robotically. In the conditions in which the .sock file is left behind after the method termination, the talked about error will happen.

READ :  throw checked Exceptions from mocks with Mockito

Easy Fixing Procedures for SocketException: Address Already in Use

You can repair the socket exception bind failed error in your system by eradicating the present mongod cases, working mongo as a substitute of mongod, or utilizing an obtainable port as a substitute of 27017. Also, restarting MongoDB or deleting the sitting .sock file may help resolve the busy port error.

– Get Rid of the Current mongod Instance

Getting rid of the present mongod occasion could make issues higher for you. But for this, you’ll must discover the method ID or PID of the mongod command. Next, you’ll have to make use of the sudo kill command to finish your present mongod occasion.

After you’ve got killed your present mongod occasion, you can begin mongod once more to see it working completely. The course of includes three steps which have been defined under.

The sudo lsof -iTCP -sTCP:LISTEN -n -P command will allow you to see the present duties working in your system. You’ll have to search out the mongod command in its output and observe its PID. Later, you’ll must run the sudo kill xxxx command by changing xxxx with the PID you famous in the earlier step. It will launch the port.

Lastly, you’ll should kind mongod to begin the server once more. However, in case you are nonetheless unable to run MongoDB, you would possibly must run mongo as a substitute of mongod.

The distinction between mongod and mongo is that the previous is the brief title for Mongo Daemon, which is the MongoDB server. On the opposite hand, the latter is an interactive JavaScript shell interface to MongoDB.

So, even when the server is already working, you gained’t face any errors in working a mongo occasion.

Note that if in case you have put in and began MongoDB by Homebrew, you may see its present cases by working the brew companies checklist command. Next, you may kill the cases by utilizing the kill command.

READ :  Error when using update between two tables joined by a code

Finally, you may create a brand new occasion by executing brew companies begin mongod or brew companies begin mongo.Fixing Procedures For Socketexception Address Already In Use

– Kill All Instances

Killing all of the earlier cases with out concentrating on their PIDs may help launch the port and remove the error listener did not set up. It means you don’t must run any instructions to see the checklist of duties, look by it, discover the PIDs, and kill the processes.

You solely have to run a single command, and will probably be sufficient to resolve the error. So, right here is how one can execute killall to scrub up the earlier cases.

– Try Running MongoDB on a Different Port

Running MongoDB on a unique port as a substitute of the default 27017 port will aid you throw away the error handle already in use. It signifies that you gained’t must waste your time ready for connections on port 27017. The new MongoDB occasion will run easily on one other obtainable port.

If you don’t thoughts utilizing a unique port, you’ll must append –port xxxx to the mongod command. Here, xxxx refers to any obtainable port like 1036, 27019, and so on. The altered command has been proven under for higher help.

– Shutdown MongoDB and Start Again

A easy but efficient methodology to repair the handle already in use error is to shut down MongoDB and begin it once more. Shutting down the server will terminate the working occasion and launch the port. Consequently, beginning the server once more on the identical port gained’t trigger any points.

This approach, you’ll be capable to take away the stated error out of your display screen. The two-step course of includes working the mongod –shutdown and mongod instructions.

– Delete the .sock File

If you’ve got already killed all of the earlier cases of MongoDB, however the error isn’t going away, then it’s best to search for and delete the .sock file. The given file can be current in the /tmp folder. You’ll should execute the ls and rm instructions to use this answer.Fix Th Error Socketexception Address Already In Use

READ :  Column Count Doesn’t Match Value Count at Row 1: MySQL Error Fixed!

To discover the acknowledged file, it’s best to run the ls command with -ltr and -a choices. It will will let you see the checklist of information contained in the tmp listing. The -ltr possibility will type the checklist in reverse order based mostly on the final modification time. Next, the -a possibility will make the hidden information seen.

You also can use grep with .sock to right away filter out the .sock file. Your ls command ought to appear like the one connected under for locating the .sock file on the earliest.

If the above command confirms the existence of the .sock file, it’s best to proceed with the rm command to eliminate it. Please be happy to rigorously run the next command in the manufacturing setting to delete the .sock file safely.

rm -f <your sock file title right here>

Conclusion

After the above dialogue, it’s clear that the given error assertion aligns completely with its trigger. The wrongdoer is both an current mongod occasion or its leftover .sock file sleeping in the /tmp folder. You can learn the bulleted checklist added under to conclude the options shared in this put up:

  • Running mongo to begin the shell as a substitute of mongod (MongoDB server) may help remove the stated error.
  • You can use one other obtainable port as a substitute of the default MongoDB port to resolve the error in the title.
  • You can discover and kill the present mongod cases to begin the brand new one with out encountering the identical error.
  • It can be useful to search for the .sock file in your system and take away it instantly to repair the busy port error.
  • If you aren’t in the temper to search out the cases, you would possibly like executing the sudo killall mongod command to cease all of the cases and get the error fastened.

Lastly, have a professional tip stating that it might be nice to get began with MongoDB Compass to carry out your database operations effectively by an interactive instrument.

References

  • https://stackoverflow.com/questions/47975929/socketexception-address-already-in-use-mongodb
  • https://stackoverflow.com/questions/4883045/mongodb-difference-between-running-mongo-and-mongod-databases

Leave a Reply

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