0

I have 2 App in same Server. One is a Flask(2.2.2) app running with Gunicorn Gevent class with Python 3.11 and another one is a python file fetcher.py that use xmlrpc.server as server running with same Python interpreter.

I sent some requests from Flask app to another one. and its work good. but sometimes im getting timeout error in Flak side.

Here is my simplified code on Flask app:

from xmlrpc import client
...
proxy = client.ServerProxy("http://localhost:8087/")
proxy.insert_free_search(json_dump)

And another App fetcher.py:

from xmlrpc import server

def main():
    serve = server.SimpleXMLRPCServer(("localhost", 8087))
    serve.register_function(insert_free_search, 'insert_free_search')
    ..
    serve.serve_forever()
    

def insert_free_search(data):
    d = json.loads(data)
    threading.Timer(0.1, insert_free_search_data,
                    [d["result"],...]).start()
    return "OK"

there is some more registered functions but for sure all of them use threading so registered functions can finish very quickly. So I'm confused why I should get timeout sometimes?

Traceback (most recent call last):
  File "/home/dashboard/dashboard/core/routes.py", line 1050, in free_search_report
    proxy.insert_free_search(s_tmp)
  File "/usr/local/lib/python3.11/xmlrpc/client.py", line 1122, in __call__
    return self.__send(self.__name, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/xmlrpc/client.py", line 1464, in __request
    response = self.__transport.request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/xmlrpc/client.py", line 1166, in request
    return self.single_request(host, handler, request_body, verbose)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/xmlrpc/client.py", line 1178, in single_request
    http_conn = self.send_request(host, handler, request_body, verbose)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/xmlrpc/client.py", line 1291, in send_request
    self.send_content(connection, request_body)
  File "/usr/local/lib/python3.11/xmlrpc/client.py", line 1321, in send_content
    connection.endheaders(request_body)
  File "/usr/local/lib/python3.11/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.11/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.11/http/client.py", line 975, in send
    self.connect()
  File "/usr/local/lib/python3.11/http/client.py", line 941, in connect
    self.sock = self._create_connection(
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dashboard/env3.11/lib/python3.11/site-packages/gevent/socket.py", line 117, in create_connection
    sock.connect(sa)    
  File "/home/dashboard/env3.11/lib/python3.11/site-packages/gevent/_socketcommon.py", line 607, in connect
    raise _SocketError(err, strerror(err))
TimeoutError: [Errno 110] Connection timed out

I dont know is it related or not but in server side sometimes I get some error too:

127.0.0.1 - - [24/May/2023 04:55:37] "POST / HTTP/1.1" 500 -
----------------------------------------
Exception occurred during processing of request from ('127.0.0.1', 47086)
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/socketserver.py", line 755, in __init__
    self.handle()
  File "/usr/local/lib/python3.11/http/server.py", line 432, in handle
    self.handle_one_request()
  File "/usr/local/lib/python3.11/http/server.py", line 421, in handle_one_request
    self.wfile.flush() #actually send the response if not already done.
    ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/socket.py", line 724, in write
    return self._sock.send(b)
           ^^^^^^^^^^^^^^^^^^
BrokenPipeError: [Errno 32] Broken pipe
A.F.N
  • 199
  • 2
  • 15
  • `Connection timed out` indicates that you have a network / firewall problem of some sort and the TCP connection is never being established. Same with `Broken pipe` - that indicates your TCP connection broke because of either of a network problem or the process on the other end of the connection closed it before this end expected it. – David K. Hess Jun 09 '23 at 14:55

0 Answers0