[SERVER-37941] specifying --bind_ip localhost results in error "address already in use" when IPv6 alias exists Created: 06/Nov/18  Updated: 29/Oct/23  Resolved: 07/Nov/18

Status: Closed
Project: Core Server
Component/s: Networking
Affects Version/s: None
Fix Version/s: 4.0.5, 4.1.5

Type: Bug Priority: Major - P3
Reporter: Mariano Escribano Assignee: Sara Golemon
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
related to SERVER-44184 De-duplicate resolved addresses on v3.6 Closed
is related to SERVER-32631 specifying --bind_ip localhost result... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0
Steps To Reproduce:

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

Sprint: Security 2018-11-19
Participants:
Case:

 Description   

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


 Comments   
Comment by Githook User [ 09/Nov/18 ]

Author:

{'name': 'Sara Golemon', 'email': 'sara.golemon@mongodb.com', 'username': 'sgolemon'}

Message: SERVER-37941 De-duplicate resolved addresses

(cherry picked from commit f62cf06d496a357b6fb3f1ca9f3174887fca302a)
Branch: v4.0
https://github.com/mongodb/mongo/commit/b412039546462ef05b84986262c9eb0c6e390a19

Comment by Githook User [ 07/Nov/18 ]

Author:

{'name': 'Sara Golemon', 'email': 'sara.golemon@mongodb.com', 'username': 'sgolemon'}

Message: SERVER-37941 De-duplicate resolved addresses
Branch: master
https://github.com/mongodb/mongo/commit/f62cf06d496a357b6fb3f1ca9f3174887fca302a

Comment by Sara Golemon [ 06/Nov/18 ]

Looks like the fix applied for SERVER-32631 is no longer valid as transport layer asio now uses its own WrappedResolver library instead of SockAddr, so we just need to apply the same de-duping logic we made for SockAddr to the loop in TransportLayerASIO::setup().

Generated at Thu Feb 08 04:47:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.