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
183 stars 43 forks source link

python-eureka-client in docker container [eureka_client]-[line:1301] -WARNING: pull full registry from eureka server error! #63

Closed markmjm closed 2 years ago

markmjm commented 2 years ago

Hi

I have a flask application that is deployed to a docker container, but i works fine in my desktop build.

Local build When I set up Eureka service (Springboot), Zuul(Springboot) and my app (Flask) on my local desktop, I see no error and I can see the app getting registered in Eureka service.

However, in the docker container, I keep running into this error show at the end. My flas setup is:

eureka_client.init( 'http://eureka1:3001/eureka/', app_name="my_flask_app", instance_port=my_flask_app_port)

inside the docker container, a curl request seems to produce the 'correct' html page, but my_flask_app is not one of this listed in this html page, which tells me that my_flask_app is not getting registed.

curl http://eureka1:3001/

I would appreciate an insight on what might be causing the error below; what additional info I need to provide in the init call?

Thanks you

Error found in Container logs

[2022-03-06 11:37:45]-[eureka_client]-[line:1301] -WARNING: pull full registry from eureka server error!
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1299, in __pull_full_registry
    self.__connect_to_eureka_server(do_pull)
  File "/usr/local/lib/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 "/usr/local/lib/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1092, in __try_eureka_server_in_cache
    fun(url)
  File "/usr/local/lib/python3.8/site-packages/py_eureka_client/eureka_client.py", line 1296, in do_pull
    self.__applications = get_applications(url, self.__remote_regions)
  File "/usr/local/lib/python3.8/site-packages/py_eureka_client/eureka_client.py", line 412, in get_applications
    return _get_applications_(f"{_format_url(eureka_server)}apps/", regions)
  File "/usr/local/lib/python3.8/site-packages/py_eureka_client/eureka_client.py", line 427, in _get_applications_
    txt = http_client.load(_url, timeout=_DEFAULT_TIME_OUT)[0]
  File "/usr/local/lib/python3.8/site-packages/py_eureka_client/http_client.py", line 146, in load
    res = http_cli.urlopen()
  File "/usr/local/lib/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/local/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/local/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/local/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.8/urllib/request.py", line 1383, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/local/lib/python3.8/urllib/request.py", line 1358, in do_open
    r = h.getresponse()
  File "/usr/local/lib/python3.8/http/client.py", line 1347, in getresponse
    response.begin()
  File "/usr/local/lib/python3.8/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.8/http/client.py", line 276, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
keijack commented 2 years ago

Have you even change your hosts file (Mostly located in /etc/hosts) to configure server name eureka1 to your loacal IP? And check in your docker container, whether that is correctly configured.

keijack commented 2 years ago

Close for long time silence, please re-open it if you have any questions.

AAyiku commented 11 months ago

Hello, I am encountering a similar issue. @keijack could you kindly give a bit more explanation to the resolution you were suggesting

keijack commented 11 months ago

@AAyiku Please upgrade to 0.11.8 and try. If errors still occur, please post the logs here.

AAyiku commented 11 months ago

Will try that out and revert

AAyiku commented 11 months ago

So this is the error that arises: [2023-09-26 11:26:19]-[HeartbeatThread]-[eureka_client:802] WARNING: pull full registry from eureka server error! Traceback (most recent call last): File "/usr/local/lib/python3.9/urllib/request.py", line 1346, in do_open h.request(req.get_method(), req.selector, req.data, headers,
File "/usr/local/lib/python3.9/http/client.py", line 1285, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/lib/python3.9/http/client.py", line 1331, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/local/lib/python3.9/http/client.py", line 1280, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/local/lib/python3.9/http/client.py", line 1040, in _send_output self.send(msg) File "/usr/local/lib/python3.9/http/client.py", line 980, in send self.connect() File "/usr/local/lib/python3.9/http/client.py", line 946, in connect self.sock = self._create_connection( File "/usr/local/lib/python3.9/socket.py", line 844, in create_connection raise err File "/usr/local/lib/python3.9/socket.py", line 832, in create_connection sock.connect(sa) OSError: [Errno 99] Address not available

During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 800, in pull_full_registry await self.connect_to_eureka_server(do_pull) File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 653, in connect_to_eureka_server await self.try_all_eureka_servers(fun) File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 616, in try_all_eureka_servers await self.try_eureka_server_in_zone(fun) File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 586, in try_eureka_server_in_zone await self.try_eureka_servers_in_list( File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 631, in try_eureka_servers_in_list await fun(url) File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_client.py", line 797, in do_pull self.applications = await get_applications(url, self.__remote_regions) File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_basic.py", line 353, in get_applications res = await _getapplications(f"{_format_url(eureka_server)}apps/", regions) File "/usr/local/lib/python3.9/site-packages/py_eureka_client/eureka_basic.py", line 370, in _getapplications res = await http_client.http_client.urlopen( File "/usr/local/lib/python3.9/site-packages/py_eureka_client/http_client.py", line 151, in urlopen res = urllib.request.urlopen(req, data=data, timeout=timeout)
File "/usr/local/lib/python3.9/urllib/request.py", line 214, in urlopen return opener.open(url, data, timeout) File "/usr/local/lib/python3.9/urllib/request.py", line 517, in open response = self._open(req, data) File "/usr/local/lib/python3.9/urllib/request.py", line 534, in _open result = self._call_chain(self.handle_open, protocol, protocol + File "/usr/local/lib/python3.9/urllib/request.py", line 494, in _call_chain result = func(*args) File "/usr/local/lib/python3.9/urllib/request.py", line 1375, in http_open return self.do_open(http.client.HTTPConnection, req) File "/usr/local/lib/python3.9/urllib/request.py", line 1349, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 99] Address not available>

AAyiku commented 11 months ago

this the eureka client initialization eureka_client.init(eureka_server="http://localhost:8082/eureka", app_name= "rec-engine", instance_port=rest_port, instance_ip="172.22.176.1")

keijack commented 11 months ago

this the eureka client initialization eureka_client.init(eureka_server="http://localhost:8082/eureka", app_name= "rec-engine", instance_port=rest_port, instance_ip="172.22.176.1")

You should not use localhost or 127.0.0.1 inside a Docker container.

AAyiku commented 11 months ago

@keijack what should I be using In this case what would the eureka_server be

keijack commented 11 months ago

You can use your local network IP or host to visit, or docker container IP which may starts with 172 or host if you use compose. Please check the basic network architecture of Docker containers.