When should the WSGI connection be closed?

I am debugging a leak in a user WSGI server based on the wsgiref.simple server, and we found that we are not closing the connection properly, so the socket is in the CLOSE_WAIT state. We use a thread pool.

This is the python library code that processes the request:

def handle(self):
    """Handle a single HTTP request"""

    self.raw_requestline = self.rfile.readline(65537)
    if len(self.raw_requestline) > 65536:
        self.requestline = ''
        self.request_version = ''
        self.command = ''
        self.send_error(414)
        return

    if not self.parse_request(): # An error code has been sent, just exit
        return

    handler = ServerHandler(
        self.rfile, self.wfile, self.get_stderr(), self.get_environ()
    )
    handler.request_handler = self      # backpointer for logging
    handler.run(self.server.get_app())

Would it be correct to override this method and close the socket if the length of self.raw_requestline is 0? ( Detect TCP Socket Status )

+4
source share

Source: https://habr.com/ru/post/1626893/


All Articles