keijack / python-eureka-client

A eureka client written in python. Support registering your python component to Eureka Server, as well as calling remote services by pulling the the Eureka registry.
MIT License
181 stars 43 forks source link

Amazon eureka client connect to eureka server often fail #86

Open wuxinke1 opened 2 months ago

wuxinke1 commented 2 months ago

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 commented 2 months ago

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

jcprietobeyond commented 1 month ago

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