Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

ping() raises instead of returning False #75

Closed
danielzgtg opened this issue Mar 11, 2020 · 1 comment
Closed

ping() raises instead of returning False #75

danielzgtg opened this issue Mar 11, 2020 · 1 comment

Comments

@danielzgtg
Copy link

The ping() method should not crash in the async version of the Elasticsearch client, and behave like the synchronous version of the client. This async version returns True properly, but raises instead of returning False.

Expected behavior

It should return a boolean like the synchronous version:

$ python3
Python 3.8.2 (default, Feb 25 2020, 13:04:52) 
[GCC 9.2.1 20200224] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import elasticsearch
>>> es = elasticsearch.Elasticsearch("127.0.0.1:9")
>>> es.ping()
False
>>>

Actual behavior

The async version raises instead of returning False:

$ python3 -m asyncio
asyncio REPL 3.8.2 (default, Feb 25 2020, 13:04:52) 
[GCC 9.2.1 20200224] on linux
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> import elasticsearch_async
>>> es = elasticsearch_async.AsyncElasticsearch("127.0.0.1:9")
>>> await es.ping()
Traceback (most recent call last):
  File "/home/home/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "/usr/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 494, in sock_connect
    return await fut
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 526, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 9)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/home/venv/lib/python3.8/site-packages/elasticsearch_async/connection.py", line 98, in perform_request
    response = yield from self.session.request(method, url, data=body, headers=headers)
  File "/home/home/venv/lib/python3.8/site-packages/aiohttp/client.py", line 480, in _request
    conn = await self._connector.connect(
  File "/home/home/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 523, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/home/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 858, in _create_connection
    _, proto = await self._create_direct_connection(
  File "/home/home/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 1004, in _create_direct_connection
    raise last_exc
  File "/home/home/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 980, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/home/home/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 943, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 127.0.0.1:9 ssl:default [Connect call failed ('127.0.0.1', 9)]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
  File "<console>", line 1, in <module>
  File "/home/home/venv/lib/python3.8/site-packages/elasticsearch_async/transport.py", line 149, in main_loop
    status, headers, data = yield from connection.perform_request(
  File "/home/home/venv/lib/python3.8/site-packages/elasticsearch_async/connection.py", line 111, in perform_request
    raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(Cannot connect to host 127.0.0.1:9 ssl:default [Connect call failed ('127.0.0.1', 9)]) caused by: ClientConnectorError(Cannot connect to host 127.0.0.1:9 ssl:default [Connect call failed ('127.0.0.1', 9)])
>>>

Environment

Nothing is listening on port 9.

Installed packages:

$ pipdeptree
elasticsearch-async==6.2.0
  - aiohttp [required: Any, installed: 3.6.2]
    - async-timeout [required: >=3.0,<4.0, installed: 3.0.1]
    - attrs [required: >=17.3.0, installed: 19.3.0]
    - chardet [required: >=2.0,<4.0, installed: 3.0.4]
    - multidict [required: >=4.5,<5.0, installed: 4.7.5]
    - yarl [required: >=1.0,<2.0, installed: 1.4.2]
      - idna [required: >=2.0, installed: 2.9]
      - multidict [required: >=4.0, installed: 4.7.5]
  - async-timeout [required: Any, installed: 3.0.1]
  - elasticsearch [required: >=6.0.0, installed: 7.5.1]
    - urllib3 [required: >=1.21.1, installed: 1.25.8]
pipdeptree==0.13.2
  - pip [required: >=6.0.0, installed: 18.1]
pkg-resources==0.0.0
setuptools==44.0.0
wheel==0.34.2
@sethmlarson
Copy link
Contributor

This issue is closed in elasticsearch[async] 7.8.0, see #81 for more information.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants