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

Cannot launch replica set with auth due to directConnection hack #859

Closed
p-mongo opened this issue Apr 12, 2022 · 2 comments
Closed

Cannot launch replica set with auth due to directConnection hack #859

p-mongo opened this issue Apr 12, 2022 · 2 comments
Assignees
Milestone

Comments

@p-mongo
Copy link
Contributor

p-mongo commented Apr 12, 2022

I am trying to launch a replica set with auth:

+ python3 -m mtools.mlaunch.mlaunch --dir /tmpfs/db --binarypath /opt/mongodb/bin --setParameter enableTestCommands=1 --setParameter acceptApiVersion2=1 --setParameter diagnosticDataCollectionEnabled=false --replicaset --name test-rs --nodes 2 --arbiter --auth --username bob --password pwd123
/opt/python37/lib/python3.7/site-packages/mtools-1.7.1.dev0-py3.7.egg/mtools/mlaunch/mlaunch.py:362: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  if (LooseVersion(self.current_version) >= LooseVersion("4.2.0")):
/opt/python37/lib/python3.7/site-packages/mtools-1.7.1.dev0-py3.7.egg/mtools/mlaunch/mlaunch.py:669: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  if (LooseVersion(self.current_version) >= LooseVersion("3.3.0") or
Generating keyfile: /tmpfs/db/keyfile
launching: "/opt/mongodb/bin/mongod" on port 27017
launching: "/opt/mongodb/bin/mongod" on port 27018
launching: "/opt/mongodb/bin/mongod" on port 27019
replica set 'test-rs' initialized.
waiting for primary to add a user.
Traceback (most recent call last):
  File "/opt/python37/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/opt/python37/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/opt/python37/lib/python3.7/site-packages/mtools-1.7.1.dev0-py3.7.egg/mtools/mlaunch/mlaunch.py", line 2226, in <module>
    sys.exit(main())
  File "/opt/python37/lib/python3.7/site-packages/mtools-1.7.1.dev0-py3.7.egg/mtools/mlaunch/mlaunch.py", line 2222, in main
    tool.run()
  File "/opt/python37/lib/python3.7/site-packages/mtools-1.7.1.dev0-py3.7.egg/mtools/mlaunch/mlaunch.py", line 620, in run
    getattr(self, self.args['command'])()
  File "/opt/python37/lib/python3.7/site-packages/mtools-1.7.1.dev0-py3.7.egg/mtools/mlaunch/mlaunch.py", line 826, in init
    if self._wait_for_primary():
  File "/opt/python37/lib/python3.7/site-packages/mtools-1.7.1.dev0-py3.7.egg/mtools/mlaunch/mlaunch.py", line 1918, in _wait_for_primary
    serverSelectionTimeoutMS=30000)
  File "/opt/python37/lib/python3.7/site-packages/mtools-1.7.1.dev0-py3.7.egg/mtools/mlaunch/mlaunch.py", line 936, in client
    return MongoConnection(host_and_port, **kwargs)
  File "/opt/python37/lib/python3.7/site-packages/mtools-1.7.1.dev0-py3.7.egg/mtools/mlaunch/mlaunch.py", line 60, in __init__
    Connection.__init__(self, *args, **kwargs)
  File "/opt/python37/lib/python3.7/site-packages/pymongo/mongo_client.py", line 753, in __init__
    _check_options(seeds, opts)
  File "/opt/python37/lib/python3.7/site-packages/pymongo/uri_parser.py", line 391, in _check_options
    raise ConfigurationError("Cannot specify multiple hosts with directConnection=true")
pymongo.errors.ConfigurationError: Cannot specify multiple hosts with directConnection=true
/home/w/apps/ruby-driver/spec/shared/lib/mrss/docker_runner.rb:168:in `run_command': Process exited with code 1 (RuntimeError)
	from /home/w/apps/ruby-driver/spec/shared/lib/mrss/docker_runner.rb:117:in `run_tests'
	from /home/w/apps/ruby-driver/spec/shared/lib/mrss/docker_runner.rb:33:in `run'
	from ./.evergreen/test-on-docker:11:in `<main>'

As far as I can tell what happens is that mlaunch has this hack to add directConnection to MongoClient constructions:

class MongoConnection(Connection):
    """
    MongoConnection class.

    Wrapper around Connection (itself conditionally a MongoClient or
    pymongo.Connection) to specify timeout and directConnection.
    """

    def __init__(self, *args, **kwargs):
        kwargs.setdefault('directConnection', True)
        kwargs.setdefault('serverSelectionTimeoutMS', 1)

        # Set client application name for MongoDB 3.4+ servers
        kwargs['appName'] = f'''mlaunch v{__version__}'''

        Connection.__init__(self, *args, **kwargs)

This hack is employed when waiting for replica set, which passes the list of all hosts to the constructor. Subsequently mlaunch tries to request direct connection to 3 nodes at the same time which pymongo rejects.

Expected behavior

The invocation above to create a replica set with auth.

Actual/current behavior

mlaunch fails to create the deployment.

Steps to reproduce the actual/current behavior

See the command quoted above.

Environment

Software Version
mtools master
Python 3.7
MongoDB server 5.0
Operating system Debian Linux testing
@stennie stennie added this to the 1.7.1 milestone Apr 12, 2022
@stennie stennie added bug and removed question labels Apr 12, 2022
@p-mongo
Copy link
Contributor Author

p-mongo commented May 24, 2022

@blink1073
Copy link
Contributor

The first two cases are covered by the change in #875, and the third seems unrelated (ismaster = con['admin'].command('isMaster')).

@stennie stennie self-assigned this Jul 18, 2022
@stennie stennie added the mlaunch label Oct 3, 2022
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