简体   繁体   中英

Flask: Server becomes unresponsive after some time

I use a flask server to serve static files from a server but once in a while the server becomes completely unresponsive, downloading a file keeps loading but never downloads. When I opened up the terminal, I found some weird requests, I hit CTRL + C and the server immediately becomes responsive again and downloads continue. This happens every so often and I have no idea what's causing this and how to prevent it from freezing my flask server, is this someone trying to hack?

user@server:~/worker# python server.py
 * Running on http://0.0.0.0:80/
93.134.13.318 - - [03/Sep/2014 02:07:18] code 400, message Bad request syntax ('\x00')
93.134.13.318 - - [03/Sep/2014 02:07:18] "" 400 -
93.134.13.318 - - [03/Sep/2014 02:07:19] "GET http://httpheader.net HTTP/1.1" 404 -
93.134.13.318 - - [03/Sep/2014 02:07:40] code 400, message Bad request syntax ('\x04\x01\x00P\xc6\xce\x0eu0\x00')
93.174.93.218 - - [03/Sep/2014 02:07:40] "P��u0" 400 -
^C----------------------------------------
Exception happened during processing of request from ('93.174.93.218 ', 45082)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 638, in __init__
    self.handle()
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 200, in handle
    rv = BaseHTTPRequestHandler.handle(self)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 231, in handle_one_request
    self.raw_requestline = self.rfile.readline()
  File "/usr/lib/python2.7/socket.py", line 447, in readline
    data = self._sock.recv(self._rbufsize)
KeyboardInterrupt
----------------------------------------
42.36.63.90 - - [03/Sep/2014 03:21:20] "GET / HTTP/1.1" 404 -
63.63.193.195 - - [03/Sep/2014 03:21:20] "GET / HTTP/1.1" 404 -

I had the same issue. It's common in django/flask apps to hang when running as python server.py, because this in not an optimal environment for them. Only use it for testing purpose. When you're done with it and want to release, you should put it behind a wsgi/uwsgi + apache/nginx and your problem will go away.

http://flask.pocoo.org/docs/0.10/deploying/uwsgi/

http://flask.pocoo.org/docs/1.0/deploying/uwsgi/

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