[SERVER-32631] specifying --bind_ip localhost results in error "address already in use" Created: 10/Jan/18  Updated: 30/Oct/23  Resolved: 12/Jan/18

Status: Closed
Project: Core Server
Component/s: Networking
Affects Version/s: 3.6.0, 3.6.1
Fix Version/s: 3.6.3, 3.7.2

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

CentOS Linux release 7.4.1708 (Core)


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

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

Participants:
Case:

 Description   

Specifying --bind_ip localhost with or without an additional ip address results in the server error:

2018-01-10T18:17:10.809+0000 I STORAGE  [initandlisten] exception in initAndListen std::exception: listen: Address already in use, terminating
2018-01-10T18:17:10.809+0000 I NETWORK  [initandlisten] shutdown: going to close listening sockets...

As a result, it is not possible to start a server that binds to both localhost and an alternate IP address.



 Comments   
Comment by Ian Sutherland [ 14/Aug/18 ]

I'm still encountering this issue with MongoDB 4.0.1, specifically when running on CircleCI. They appear to be running Ubuntu 14.04.1.

Comment by Githook User [ 28/Jan/18 ]

Author:

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

Message: SERVER-32631 Deduplicate results in SockAddr::createAll()

(cherry picked from commit 62c9eedec658912f796f5bcdb25f57891e4069ca)
(cherry picked from commit 22f10748b1561f55cd053c9a1b3aba00b83adfc9)
Branch: v3.6
https://github.com/mongodb/mongo/commit/08fe3aba7e9a5c8fa54426b68a503a852312d004

Comment by Sara Golemon [ 12/Jan/18 ]

Thanks for the report. It turns out getaddrinfo() does something surprising when asked for IPv4 addresses only, and there are localhost entries for both IPv4 and IPv6. We're going to deal with this by simply de-duping the response, allowing us to tell the difference between an address in use by another application versus an address in use by ourselves. This fix is on the main development branch currently and should shortly be backported to 3.6.

Comment by Githook User [ 12/Jan/18 ]

Author:

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

Message: SERVER-32631 Deduplicate results in SockAddr::createAll()
Branch: master
https://github.com/mongodb/mongo/commit/62c9eedec658912f796f5bcdb25f57891e4069ca

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