#community-help

Typesense Connection Error on AWS EC2 Instance

TLDR Raj reported an error related to Typesense in AWS EC2 instance. After several suggestions, the issue was resolved by changing the TYPESENSE_HOST value in the .env file from "localhost" to "127.0.0.1".

Powered by Struct AI

1

9
6mo
Solved
Join the chat
Jun 08, 2023 (6 months ago)
Raj
Photo of md5-fd3186ce27b535ef0b49080da4844d31
Raj
09:49 AM
Hello, I installed typesense in AWS EC2 instance.. curl localhost:8108/health >> returned {ok:true}. My next step is running the docsearch crawler..

Below is my env file
TYPESENSE_API_KEY=xyz
TYPESENSE_HOST=host.docker.internal
TYPESENSE_PORT=8108
TYPESENSE_PROTOCOL=http

Below is the error I am getting while running docker run command

traceback (most recent call last):
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/urllib3/util/connection.py", line 72, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/lib/python3.10/socket.py", line 955, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/urllib3/connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1037, in _send_output
self.send(msg)
File "/usr/lib/python3.10/http/client.py", line 975, in send
self.connect()
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/urllib3/connection.py", line 205, in connect
conn = self._new_conn()
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/urllib3/connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fd4f7f63a60>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='host.docker.internal', port=8108): Max retries exceeded with url: /collections/support2_1686217630 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd4f7f63a60>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/seleuser/src/index.py", line 117, in <module>
run_config(environ['CONFIG'])
File "/home/seleuser/src/index.py", line 44, in run_config
typesense_helper.create_tmp_collection()
File "/home/seleuser/src/typesense_helper.py", line 32, in create_tmp_collection
self.typesense_client.collections[self.collection_name_tmp].delete()
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/typesense/collection.py", line 22, in delete
return self.api_call.delete(self._endpoint_path())
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/typesense/api_call.py", line 158, in delete
return self.make_request(requests.delete, endpoint, True,
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/typesense/api_call.py", line 129, in make_request
raise last_exception
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/typesense/api_call.py", line 103, in make_request
r = fn(url, headers={ApiCall.API_KEY_HEADER_NAME: self.config.api_key}, **kwargs)
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/requests/api.py", line 157, in delete
return request("delete", url, **kwargs)
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/home/seleuser/.local/share/virtualenvs/seleuser-AdYDHarm/lib/python3.10/site-packages/requests/adapters.py", line 565, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='host.docker.internal', port=8108): Max retries exceeded with url: /collections/support2_1686217630 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd4f7f63a60>: Failed to establish a new connection: [Errno -2] Name or service not known'))

Jason As suggested in this thread https://github.com/typesense/typesense/issues/668, I added inbound/outbound rules to allow port8108 with 0.0.0.0/0 but issue is not resolved..
Sergio
Photo of md5-19856b8e92142bdd0747d7a3706736c8
Sergio
10:09 AM
So you are running Typesense in a EC2 with Docker? Or are you only running docsearch in Docker?
Raj
Photo of md5-fd3186ce27b535ef0b49080da4844d31
Raj
10:36 AM
Typesnese is already installed and running in EC2. I want to run scraping job by running below command in EC2.

$ docker run -it --env-file=/path/to/your/.env -e "CONFIG=$(cat config.json | jq -r tostring)" typesense/docsearch-scraper:0.6.0
Sergio
Photo of md5-19856b8e92142bdd0747d7a3706736c8
Sergio
10:55 AM
Try adding --network="host" like this
docker run -it --env-file=/path/to/your/.env -e "CONFIG=$(cat config.json | jq -r tostring)" --network="host" typesense/docsearch-scraper:0.6.0
Raj
Photo of md5-fd3186ce27b535ef0b49080da4844d31
Raj
07:54 PM
no luck.. returned the same error..
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:58 PM
Could you try adding this docker flag: https://stackoverflow.com/a/62431165/123545
07:59
Jason
07:59 PM
(and remove --network="host" if you’re using the flag above)
Jun 13, 2023 (6 months ago)
Raj
Photo of md5-fd3186ce27b535ef0b49080da4844d31
Raj
02:20 AM
Issue is resolved after I modify the value of TYPESENSE_HOST of .env file from localhost to 127.0.0.1

thank you Sergio Jason

1

Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
02:27 AM
Good to know! Thank you for sharing

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3011 threads (79% resolved)

Join Our Community