Skip to content

sbin/search.sh --count fails due to MongoDB replica error #1519

@coderabbitai

Description

@coderabbitai

Problem Description

Running ./sbin/search.sh --count fails with the error:

Traceback (most recent call last):
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/opt/clp/lib/python3/site-packages/clp_package_utils/scripts/native/search.py", line 83, in create_and_monitor_job_in_db
    for document in search_results_collection.find():
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/cursor.py", line 1289, in __next__
    return self.next()
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/cursor.py", line 1265, in next
    if len(self._data) or self._refresh():
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/cursor.py", line 1213, in _refresh
    self._send_message(q)
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/cursor.py", line 1108, in _send_message
    response = client._run_operation(
  File "/opt/clp/lib/python3/site-packages/pymongo/_csot.py", line 125, in csot_wrapper
    return func(self, *args, **kwargs)
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/mongo_client.py", line 1938, in _run_operation
    return self._retryable_read(
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/mongo_client.py", line 2047, in _retryable_read
    return self._retry_internal(
  File "/opt/clp/lib/python3/site-packages/pymongo/_csot.py", line 125, in csot_wrapper
    return func(self, *args, **kwargs)
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/mongo_client.py", line 2014, in _retry_internal
    ).run()
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/mongo_client.py", line 2765, in run
    return self._read() if self._is_read else self._write()
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/mongo_client.py", line 2910, in _read
    self._server = self._get_server()
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/mongo_client.py", line 2858, in _get_server
    return self._client._select_server(
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/mongo_client.py", line 1833, in _select_server
    server = topology.select_server(
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/topology.py", line 409, in select_server
    server = self._select_server(
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/topology.py", line 387, in _select_server
    servers = self.select_servers(
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/topology.py", line 294, in select_servers
    server_descriptions = self._select_servers_loop(
  File "/opt/clp/lib/python3/site-packages/pymongo/synchronous/topology.py", line 344, in _select_servers_loop
    raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: Could not reach any servers in [('results_cache', 27017)]. Replica set is configured with internal hostnames or IPs?, Timeout: 30s, Topology Description: <TopologyDescription id: 69014b257a2094eabbc79092, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('results_cache', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('results_cache:27017: [Errno -3] Temporary failure in name resolution (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)')>]>

The results-cache MongoDB client in components/clp-package-utils/clp_package_utils/scripts/native/search.py fails to properly initialize when connecting to read query aggregation results from the result cache.

Root Cause

The results cache is provisioned as a single-node replica with an in-container hostname. Without specifying directConnection=True in the MongoDB client initialization, the Mongo server acts as a proxy and attempts to resolve the given host during initialization before making connections. This behaviour prevents proper connection establishment.

Impact

This affects the ability to read aggregation outputs from the results cache, preventing query results from being retrieved properly.

Resolution

Fixed by PR #1518


Reported by: @quinntaylormitchell
Related PR: #1518

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions