简体   繁体   中英

Tornado connections not closing in freeBSD

I have a tornado web server, something like :

app = tornado.web.Application(handlersList,log_function=printIt)
app.listen(port)
serverInstance = tornado.ioloop.IOLoop.instance()  
serverInstance.start()

the handlers are made with tornado.web.RequestHandler . When I run the server on freeBSD, sometimes the page/resource takes long time to load, trying to debug I see that when waiting for page to load Tornado didn't create a request object yet, and looking at netstat results, I see a lot of connection with status ESTABLISHED.

So my thought is that there are too many not closed connection, and operating system refuse new connection coming from the same session.

Can this be the case?

I don't do anything in get,post functions after writing, should I somehow shutdown/close the connection before returning?

EDIT 1: get/post are synchronous (no @asynchronous)

EDIT 2: temporarily fixed by forcing no_keep_alive

class BasicFeedHandler(tornado.web.RequestHandler):

    def finish(self, chunk=None):
        self.request.connection.no_keep_alive = True
        tornado.web.RequestHandler.finish(self, chunk) 

I'm not sure if keep_alive connections should stay open so long after client closed connection, any way this workaround works.
I found how to do this by looking at HTTPConnection._finish_request , when no keep-alive this line self.stream.read_until(b("\\r\\n\\r\\n"), self._header_callback) runs. what is \\r\\n\\r\\n in this context ?

Try this:

class Application(tornado.web.Application):
    def __init__(self):
        ...

http_server = tornado.httpserver.HTTPServer(Application(),no_keep_alive=True)
http_server.listen(port)
tornado.ioloop.IOLoop.instance().start()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM