Skip to content

st2api pod cannot connect to mongo service #355

@guzzijones

Description

@guzzijones

Initially we were recieving the dreaded no replica sets found. I increased all the timeouts and now we are getting the following:

vagrant@devbox:~/stackstorm-k8s$ kubectl logs stackstorm-ha-st2api-5c84c8b77c-c22v5
2023-01-31 20:52:17,451 INFO [-] Using Python: 3.8.10 (/opt/stackstorm/st2/bin/python)
2023-01-31 20:52:17,452 INFO [-] Using fs encoding: utf-8, default encoding: utf-8, locale: en_US.UTF-8, LANG env variable: en_US.UTF-8, PYTHONIOENCODING env variable: notset
2023-01-31 20:52:17,452 INFO [-] Using config files: /etc/st2/st2.conf,/etc/st2/st2.docker.conf,/etc/st2/st2.user.conf
2023-01-31 20:52:17,452 INFO [-] Using logging config: /etc/st2/logging.api.gunicorn.conf
2023-01-31 20:52:17,453 INFO [-] Using coordination driver: redis
2023-01-31 20:52:17,453 INFO [-] Using metrics driver: noop
2023-01-31 20:52:17,469 INFO [-] Connecting to database "st2" @ "stackstorm-ha-mongodb-0.stackstorm-ha-mongodb-headless:27017,stackstorm-ha-mongodb-1.stackstorm-ha-mongodb-headless:27017,stackstorm-ha-mongodb-2.stackstorm-ha-mongodb-headless:27017 (replica set)" as user "st2-admin".
2023-01-31 20:52:29,675 ERROR [-] Failed to connect to database "st2" @ "stackstorm-ha-mongodb-0.stackstorm-ha-mongodb-headless:27017,stackstorm-ha-mongodb-1.stackstorm-ha-mongodb-headless:27017,stackstorm-ha-mongodb-2.stackstorm-ha-mongodb-headless:27017 (replica set)" as user "st2-admin": stackstorm-ha-mongodb-2.stackstorm-ha-mongodb-headless:27017: [Errno -2] Name or service not known,stackstorm-ha-mongodb-0.stackstorm-ha-mongodb-headless:27017: [Errno -2] Name or service not known, Timeout: 12.0s, Topology Description: <TopologyDescription id: 63d97f812d1fa52f9c889a95, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('stackstorm-ha-mongodb-0.stackstorm-ha-mongodb-headless', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('stackstorm-ha-mongodb-0.stackstorm-ha-mongodb-headless:27017: [Errno -2] Name or service not known')>, <ServerDescription ('stackstorm-ha-mongodb-1.stackstorm-ha-mongodb-headless', 27017) server_type: Unknown, rtt: None>, <ServerDescription ('stackstorm-ha-mongodb-2.stackstorm-ha-mongodb-headless', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('stackstorm-ha-mongodb-2.stackstorm-ha-mongodb-headless:27017: [Errno -2] Name or service not known')>]>
2023-01-31 20:52:29,675 ERROR [-] (PID=1) ST2 API quit due to exception.
Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2api/cmd/api.py", line 98, in main
    _setup()
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2api/cmd/api.py", line 60, in _setup
    common_setup(
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/service_setup.py", line 252, in setup
    db_setup()
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/database_setup.py", line 55, in db_setup
    connection = db_init.db_setup_with_retry(**db_cfg)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/persistence/db_init.py", line 79, in db_setup_with_retry
    return db_func_with_retry(
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/persistence/db_init.py", line 58, in db_func_with_retry
    return retrying_obj.call(db_func, *args, **kwargs)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/retrying.py", line 206, in call
    return attempt.get(self._wrap_exception)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/retrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/six.py", line 696, in reraise
    raise value
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/models/db/__init__.py", line 243, in db_setup
    connection = _db_connect(
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/models/db/__init__.py", line 217, in _db_connect
    raise e
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/st2common/models/db/__init__.py", line 208, in _db_connect
    connection.admin.command("ping")
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/pymongo/database.py", line 736, in command
    with self.__client._socket_for_reads(
  File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1325, in _socket_for_reads
    server = self._select_server(read_preference, session)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1278, in _select_server
    server = topology.select_server(server_selector)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/pymongo/topology.py", line 241, in select_server
    return random.choice(self.select_servers(selector,
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/pymongo/topology.py", line 199, in select_servers
    server_descriptions = self._select_servers_loop(
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/pymongo/topology.py", line 215, in _select_servers_loop
    raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: stackstorm-ha-mongodb-2.stackstorm-ha-mongodb-headless:27017: [Errno -2] Name or service not known,stackstorm-ha-mongodb-0.stackstorm-ha-mongodb-headless:27017: [Errno -2] Name or service not known, Timeout: 12.0s, Topology Description: <TopologyDescription id: 63d97f812d1fa52f9c889a95, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('stackstorm-ha-mongodb-0.stackstorm-ha-mongodb-headless', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('stackstorm-ha-mongodb-0.stackstorm-ha-mongodb-headless:27017: [Errno -2] Name or service not known')>, <ServerDescription ('stackstorm-ha-mongodb-1.stackstorm-ha-mongodb-headless', 27017) server_type: Unknown, rtt: None>, <ServerDescription ('stackstorm-ha-mongodb-2.stackstorm-ha-mongodb-headless', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('stackstorm-ha-mongodb-2.stackstorm-ha-mongodb-headless:27017: [Errno -2] Name or service not known')>]>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions