elastic-transport-python icon indicating copy to clipboard operation
elastic-transport-python copied to clipboard

Exception on NodePool._dead_nodes

Open floxay opened this issue 2 years ago • 0 comments

Traceback:

  File "C:\Users\x\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py", line 605, in _wait_for_one
    return f.result()  # May raise f.exception().
           ^^^^^^^^^^
  File "C:\Users\x\AppData\Local\Programs\Python\Python311\Lib\site-packages\elasticsearch\_async\client\__init__.py", line 3865, in search
    return await self.perform_request(  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\x\AppData\Local\Programs\Python\Python311\Lib\site-packages\elasticsearch\_async\client\_base.py", line 285, in perform_request
    meta, resp_body = await self.transport.perform_request(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\x\AppData\Local\Programs\Python\Python311\Lib\site-packages\elastic_transport\_async_transport.py", line 311, in perform_request
    self.node_pool.mark_dead(node)
  File "C:\Users\x\AppData\Local\Programs\Python\Python311\Lib\site-packages\elastic_transport\_node_pool.py", line 245, in mark_dead
    self._dead_nodes.put((now + timeout, node))
  File "C:\Users\x\AppData\Local\Programs\Python\Python311\Lib\queue.py", line 150, in put
    self._put(item)
  File "C:\Users\x\AppData\Local\Programs\Python\Python311\Lib\queue.py", line 236, in _put
    heappush(self.queue, item)
TypeError: '<' not supported between instances of 'AiohttpHttpNode' and 'AiohttpHttpNode'

Code: https://github.com/elastic/elastic-transport-python/blob/01d05d37531531dacd3333b4bdcee22a75b21a75/elastic_transport/_node_pool.py#L245 + likely all other places where the queue is accessed/modified.

To my understanding this happens because the timestamp (first item in the tuple) is not unique and because of this an unimplemented < comparison is attempted on the next item of the tuple, which is the node object.

From Common Sequence Operations:

Sequences of the same type also support comparisons. In particular, tuples and lists are compared lexicographically by comparing corresponding elements. This means that to compare equal, every element must compare equal and the two sequences must be of the same type and have the same length. (For full details see Comparisons in the language reference.)

floxay avatar Sep 07 '23 22:09 floxay