Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-37941

specifying --bind_ip localhost results in error "address already in use" when IPv6 alias exists

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.0.5, 4.1.5
    • Affects Version/s: None
    • Component/s: Networking
    • None
    • Fully Compatible
    • ALL
    • v4.0
    • Hide

      Assuming the following /etc/hosts file:

      # cat /etc/hosts
      127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
      ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

      mongod --bind_ip localhost --dbpath data --logpath mongod.log
      or
      mongod --bind_ip localhost,10.0.2.15 --dbpath data --logpath mongod.log

      Show
      Assuming the following /etc/hosts file: # cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 mongod --bind_ip localhost --dbpath data --logpath mongod.log or mongod --bind_ip localhost,10.0.2.15 --dbpath data --logpath mongod.log
    • Security 2018-11-19

      Specifying --bind_ip localhost with or without an additional ip address results in the server error below and the mongod fails to start:

      2018-11-06T10:23:07.682-0600 I STORAGE [initandlisten] exception in initAndListen std::exception: listen: Address already in use, terminating
      2018-11-06T10:23:07.682-0600 I NETWORK [initandlisten] shutdown: going to close listening sockets...

      This is due to the `localhost` alias being used for both IPv4 and IPv6 loopback addresses in /etc/hosts.

      The following workarounds are available:

      1. Use localhost4 or some other unique alias in /etc/hosts for 127.0.0.1
      2. Use the loopback address directly 127.0.0.1 instead of an alias shared by both 127.0.0.1 and ::1
      3. Comment out or remove matching IPv6 aliases in /etc/hosts if IPv6 is not currently in use

      This was tested on the following release:

      1. mongod --version
        db version v4.0.3
        git version: 7ea530946fa7880364d88c8d8b6026bbc9ffa48c
        OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
        allocator: tcmalloc
        modules: enterprise
        build environment:
        distmod: rhel62
        distarch: x86_64
        target_arch: x86_64

            Assignee:
            sara.golemon@mongodb.com Sara Golemon
            Reporter:
            mariano.escribano@mongodb.com Mariano Escribano
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: