python-eureka-client icon indicating copy to clipboard operation
python-eureka-client copied to clipboard

Amazon eureka client connect to eureka server often fail

Open wuxinke1 opened this issue 1 year ago • 2 comments

Recently, this error often appears, why is this? `[2024-05-06 05:37:33]-[eureka_client]-[line:1147] -WARNING: Eureka server [http://127.0.0.1:7001/eureka] is down, use next url to try. Traceback (most recent call last): File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1161, in __connect_to_eureka_server self.__try_eureka_server_in_cache(fun) File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1103, in __try_eureka_server_in_cache raise EurekaServerConnectionException("All eureka servers in cache are down!") py_eureka_client.eureka_client.EurekaServerConnectionException: <urlopen error All eureka servers in cache are down!>

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1145, in __try_eureka_servers_in_list fun(url) File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1247, in do_send_heartbeat send_heartbeat(url, self.__instance["app"], File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 384, in send_heartbeat http_client.load(req, timeout=_DEFAULT_TIME_OUT)[0] File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/http_client.py", line 146, in load res = http_cli.urlopen() File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/http_client.py", line 111, in urlopen return urllib.request.urlopen(self.request, data=self.data, timeout=self.timeout, File "/usr/lib64/python3.8/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/usr/lib64/python3.8/urllib/request.py", line 531, in open response = meth(req, response) File "/usr/lib64/python3.8/urllib/request.py", line 640, in http_response response = self.parent.error( File "/usr/lib64/python3.8/urllib/request.py", line 569, in error return self._call_chain(*args) File "/usr/lib64/python3.8/urllib/request.py", line 502, in _call_chain result = func(*args) File "/usr/lib64/python3.8/urllib/request.py", line 649, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 404: [2024-05-06 05:37:33]-[eureka_client]-[line:1252] -WARNING: Cannot send heartbeat to server, try to register. Traceback (most recent call last): File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1161, in __connect_to_eureka_server self.__try_eureka_server_in_cache(fun) File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1103, in __try_eureka_server_in_cache raise EurekaServerConnectionException("All eureka servers in cache are down!") py_eureka_client.eureka_client.EurekaServerConnectionException: <urlopen error All eureka servers in cache are down!>

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1131, in __try_all_eureka_servers self.__try_eureka_server_in_zone(fun) File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1106, in __try_eureka_server_in_zone self.__try_eureka_servers_in_list(fun, self.__eureka_server_conf.servers_in_zone, self.zone) File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1156, in __try_eureka_servers_in_list raise EurekaServerConnectionException(f"All eureka servers in zone[{_zone}] are down!") py_eureka_client.eureka_client.EurekaServerConnectionException: <urlopen error All eureka servers in zone[default] are down!>

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1250, in send_heartbeat self.__connect_to_eureka_server(do_send_heartbeat) File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1163, in __connect_to_eureka_server self.__try_all_eureka_servers(fun) File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1133, in __try_all_eureka_servers self.__try_eureka_server_not_in_zone(fun) File "/py3.8/lib64/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1116, in __try_eureka_server_not_in_zone raise EurekaServerConnectionException("All eureka servers in all zone are down!") py_eureka_client.eureka_client.EurekaServerConnectionException: <urlopen error All eureka servers in all zone are down!>`

wuxinke1 avatar May 20 '24 09:05 wuxinke1

Hi @keijack, eureka client connect to eureka server often fail on an Amazon environment, but it was working before.

wuxinke1 avatar May 20 '24 10:05 wuxinke1

I'd the same problem because a was getting the URL from a variable in Spring Config Server shared with others Java microservices (eureka.cliente.serviceUrl.defaultZone), and the format of URI isn't the same.

Doing this, this was solved:

eureka_client.init(eureka_server=os.getenv('EUREKASERVER', default='localhost') + ":8761/eureka",
                       eureka_protocol="http",
                       eureka_basic_auth_user=eureka_config['user'],
                       eureka_basic_auth_password=eureka_config['pwd'],
                       app_name=app_name,
                       instance_id=app_name + ":" + app_version + ":" + secrets.token_hex(15),
                       instance_port=port)

Where EUREKASERVER may be the IP of Eureka or theis URL getted from a enviroment variable

jcprietobeyond avatar May 28 '24 13:05 jcprietobeyond