3

I have a newly installed version of MongoDB (v3.2.0) on my Mac. When I try running the command mongod I get this error:

listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017

Even though the result of $ lsof -i :27017shows nothing is using that port.

Here is the terminal output:

Michaels-iMac:~ michael$ mongod
    2016-01-07T13:38:00.097+0000 I CONTROL  [initandlisten] MongoDB starting : pid=11485 port=27017 dbpath=/data/db 64-bit host=Michaels-iMac.home
    2016-01-07T13:38:00.097+0000 I CONTROL  [initandlisten] db version v3.2.0
    2016-01-07T13:38:00.097+0000 I CONTROL  [initandlisten] git version: 45d947729a0315accb6d4f15a6b06be6d9c19fe7
    2016-01-07T13:38:00.098+0000 I CONTROL  [initandlisten] allocator: system
    2016-01-07T13:38:00.098+0000 I CONTROL  [initandlisten] modules: none
    2016-01-07T13:38:00.098+0000 I CONTROL  [initandlisten] build environment:
    2016-01-07T13:38:00.098+0000 I CONTROL  [initandlisten]     distarch: x86_64
    2016-01-07T13:38:00.098+0000 I CONTROL  [initandlisten]     target_arch: x86_64
    2016-01-07T13:38:00.098+0000 I CONTROL  [initandlisten] options: {}
    2016-01-07T13:38:00.098+0000 E NETWORK  [initandlisten] listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
    2016-01-07T13:38:00.098+0000 E NETWORK  [initandlisten]   addr already in use
    2016-01-07T13:38:00.098+0000 E STORAGE  [initandlisten] Failed to set up sockets during startup.
    2016-01-07T13:38:00.098+0000 I CONTROL  [initandlisten] dbexit:  rc: 48
    Michaels-iMac:~ michael$ 

What am I missing here?

radiovisual
  • 6,298
  • 1
  • 26
  • 41
  • Try with `sudo lsof -i :27017`. There might be mongods not started with the euid of your user. – Markus W Mahlberg Jan 07 '16 at 14:14
  • That was good advice @MarkusWMahlberg. I tried that, but it still shows no processes running on that port. – radiovisual Jan 07 '16 at 14:27
  • Do a `telnet localhost 27017` and see what happens. – Markus W Mahlberg Jan 07 '16 at 14:37
  • well, now it is magically running. All I did was delete the `/data/db` and make a new `/data/db` and ensured proper permissions, and now it's working. Still not sure what that would have to do with the original error through. Thanks for your willingness to help @MarkusWMahlberg. If you want to add an answer of 'things you can try' in this situation, I can mark it as the answer, because you were giving good advice that could help others in the future. – radiovisual Jan 07 '16 at 14:49
  • The original error could have been a socket linger. See the answer to http://stackoverflow.com/questions/3757289/tcp-option-so-linger-zero-when-its-required and `man setsockopt`. – cdarke Jan 07 '16 at 20:50
  • Thanks for the advice, @cdarke. I actually think that a socket linger is a good possibility. Next time this happens, I will take that into consideration. – radiovisual Jan 09 '16 at 18:35
  • Possible duplicate of [Unable to start MongoDB. ERROR: addr already in use](http://stackoverflow.com/questions/28253384/unable-to-start-mongodb-error-addr-already-in-use) – Dmitri Zaitsev Mar 04 '17 at 11:25

0 Answers0