Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mlaunch: Launching IPv6-only should not try to connect via IPv4 localhost #798

Open
rcsanchez97 opened this issue Apr 21, 2020 · 1 comment

Comments

@rcsanchez97
Copy link

In using mlaunch to launch a replica set in order to reproduce a bug reported by a user, an unexpected failure resulted. The problem appears to originate from configuring the MongoDB servers to only bind to IPv6 addresses. It appears that mlaunch successfully launches the MongoDB servers, but then cannot connect to them on the expected localhost IPv4 address.

The command and output are:

admin@ip-10-122-9-40:~$ mlaunch init --replicaset --nodes=2 --hostname localhost --binarypath ./mongodb-linux-x86_64-enterprise-debian10-4.5.0-814-g7d2d87c/bin --dir ./rs2 --ipv6 --bind_ip ::1
launching: "./mongodb-linux-x86_64-enterprise-debian10-4.5.0-814-g7d2d87c/bin/mongod" on port 27017
launching: "./mongodb-linux-x86_64-enterprise-debian10-4.5.0-814-g7d2d87c/bin/mongod" on port 27018
Traceback (most recent call last):
  File "/usr/local/bin/mlaunch", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/dist-packages/mtools/mlaunch/mlaunch.py", line 2068, in main
    tool.run()
  File "/usr/local/lib/python3.7/dist-packages/mtools/mlaunch/mlaunch.py", line 542, in run
    getattr(self, self.args['command'])()
  File "/usr/local/lib/python3.7/dist-packages/mtools/mlaunch/mlaunch.py", line 715, in init
    self._initiate_replset(nodes[0], self.args['name'])
  File "/usr/local/lib/python3.7/dist-packages/mtools/mlaunch/mlaunch.py", line 1676, in _initiate_replset
    rs_status = con['admin'].command({'replSetGetStatus': 1})
  File "/usr/lib/python3/dist-packages/pymongo/database.py", line 611, in command
    read_preference) as (sock_info, slave_ok):
  File "/usr/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/usr/lib/python3/dist-packages/pymongo/mongo_client.py", line 1099, in _socket_for_reads
    server = topology.select_server(read_preference)
  File "/usr/lib/python3/dist-packages/pymongo/topology.py", line 224, in select_server
    address))
  File "/usr/lib/python3/dist-packages/pymongo/topology.py", line 183, in select_servers
    selector, server_timeout, address)
  File "/usr/lib/python3/dist-packages/pymongo/topology.py", line 199, in _select_servers_loop
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

Here is the evidence that the severs were launched:

admin@ip-10-122-9-40:~$ ps aux |grep [m]ongo
admin     1488  1.5  0.6 1578808 107884 ?      Sl   20:44   0:01 ./mongodb-linux-x86_64-enterprise-debian10-4.5.0-814-g7d2d87c/bin/mongod --replSet replset --dbpath /home/admin/rs2/replset/rs1/db --logpath /home/admin/rs2/replset/rs1/mongod.log --port 27017 --fork --ipv6 --bind_ip ::1 --wiredTigerCacheSizeGB 1
admin     1533  1.6  0.6 1578808 107956 ?      Sl   20:44   0:01 ./mongodb-linux-x86_64-enterprise-debian10-4.5.0-814-g7d2d87c/bin/mongod --replSet replset --dbpath /home/admin/rs2/replset/rs2/db --logpath /home/admin/rs2/replset/rs2/mongod.log --port 27018 --fork --ipv6 --bind_ip ::1 --wiredTigerCacheSizeGB 1
admin@ip-10-122-9-40:~$ sudo netstat -anput |grep LISTEN
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/init
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      666/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      917/exim4
tcp        0      0 0.0.0.0:10245           0.0.0.0:*               LISTEN      695/iceccd
tcp6       0      0 ::1:27017               :::*                    LISTEN      1488/./mongodb-linu
tcp6       0      0 ::1:27018               :::*                    LISTEN      1533/./mongodb-linu
tcp6       0      0 :::111                  :::*                    LISTEN      1/init
tcp6       0      0 :::22                   :::*                    LISTEN      666/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      917/exim4
tcp6       0      0 :::2306                 :::*                    LISTEN      1037/curator

Expected behavior

mlaunch should attempt to connect to the launched servers on the configured IPv6 address.

Actual/current behavior

mlaunch only attempts to connect to the launched servers on the localhost IPv4 address, which results in a connection timeout.

Steps to reproduce the actual/current behavior

See above command and associated output.

Environment

Software Version
mtools 1.6.3
Python 3.7.3
MongoDB server 4.5.0
Operating system Debian 10
@ShaneHarvey
Copy link
Contributor

ShaneHarvey commented Apr 21, 2020

At first glance it seems like this is a PyMongo "feature". When connecting to "localhost" pymongo will only resolve IPv4: https://jira.mongodb.org/browse/PYTHON-356

To workaround pymongo's behavior here, the user needs to pass a non-"localhost" --hostname and mlaunch needs to change to connect with the hostname instead of hard coding "localhost". For example:
https://github.com/p-mongo/mtools/blob/b932e763fb59b9b20972036ea792e0d58b024aba/mtools/mlaunch/mlaunch.py#L86

host = 'localhost:%i' % port

Needs to change to:

host = '%s:%s' % (args['hostname'], port)

I've opened PYTHON-2209 to see if we can make PyMongo more user friendly here but I'm not sure if it will be possible.

@stennie stennie added this to the 1.7.0 milestone Oct 12, 2020
@stennie stennie self-assigned this Oct 12, 2020
@stennie stennie removed their assignment Jan 18, 2021
@stennie stennie changed the title Launching IPv6-only appears to confuse mtools mlaunch: Launching IPv6-only should not try to connect via IPv4 localhost Nov 27, 2021
@stennie stennie added the bug label Nov 27, 2021
@stennie stennie removed this from the 1.7.0 milestone Nov 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants