• 0

Flask web server won't respond


Question

I am running a Flask web app on an Ubuntu machine in an Amazon EC2 instance and I have been noticing that when I try to access the site, it just hangs and doesn't load the index.html file. The app in question has a web form and submits a URL to the server for processing (only validates if URL is between 10 and 30 characters).

This problem occurs after the server has been running for some time, but there is no consistency. It could be a few hours, to days.

I have some log entries which indicate some suspicious activity but I am not really sure how to mitigate it. I believe someone is sending garbage requests which is overloading Flask. Log entries are below, IP addresses have been masked.

Log #1

    xxx.xxx.xxx.xxx - - [31/Oct/2015 02:27:03] "CONNECT mail.mktrn.net:25 HTTP/1.1" 404 -
    xxx.xxx.xxx.xxx - - [31/Oct/2015 03:33:53] "GET /manager/html HTTP/1.1" 404 -
    xxx.xxx.xxx.xxx - - [31/Oct/2015 03:38:29] code 400, message Bad request syntax ('\x00')
    xxx.xxx.xxx.xxx - - [31/Oct/2015 03:38:29] " " 400 -
    xxx.xxx.xxx.xxx - - [31/Oct/2015 03:38:32] "GET http://httpheader.net/ HTTP/1.1" 200 -
    xxx.xxx.xxx.xxx - - [31/Oct/2015 03:38:52] code 400, message Bad request syntax ('\x04\x01\x00P\xc0c\xf660\x00')
    xxx.xxx.xxx.xxx - - [31/Oct/2015 03:38:52] " PÀcö60 " 400 -
    xxx.xxx.xxx.xxx - - [31/Oct/2015 03:39:12] code 400, message Bad request syntax ('\x05\x01\x00')
    xxx.xxx.xxx.xxx - - [31/Oct/2015 03:39:12] " " 400 -
    xxx.xxx.xxx.xxx - - [31/Oct/2015 05:10:44] "GET /manager/html HTTP/1.1" 404 -
    xxx.xxx.xxx.xxx - - [31/Oct/2015 06:02:10] "OPTIONS / HTTP/1.1" 200 -
    xxx.xxx.xxx.xxx - - [31/Oct/2015 09:39:47] "GET /manager/html HTTP/1.1" 404 -
    xxx.xxx.xxx.xxx - - [31/Oct/2015 11:24:04] "GET /manager/html HTTP/1.1" 404 -
    xxx.xxx.xxx.xxx - - [31/Oct/2015 12:24:48] "GET http://www.google.com/reader/about/ HTTP/1.1" 404 - [/code] Log #2 [code]     xxx.xxx.xxx.xxx - - [28/Oct/2015 05:08:54] "POST http://check.best-proxies.ru/azenv.php?auth=144600890911134&a=PC&i=873992700&p=8080 HTTP/1.1" 404 -     xxx.xxx.xxx.xxx - - [28/Oct/2015 05:08:54] "CONNECT check.best-proxies.ru:80 HTTP/1.1" 404 -     xxx.xxx.xxx.xxx - - [28/Oct/2015 05:09:04] code 400, message Bad request syntax ('\x04\x01\x00P\x05\xb2VL0\x00')     xxx.xxx.xxx.xxx - - [28/Oct/2015 05:09:04] " P²VL0 " 400 -     Traceback (most recent call last):       File "/home/ubuntu/anaconda/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock         self.process_request(request, client_address)       File "/home/ubuntu/anaconda/lib/python2.7/SocketServer.py", line 321, in process_request         self.finish_request(request, client_address)       File "/home/ubuntu/anaconda/lib/python2.7/SocketServer.py", line 334, in finish_request         self.RequestHandlerClass(request, client_address, self)       File "/home/ubuntu/anaconda/lib/python2.7/SocketServer.py", line 657, in __init__         self.finish()       File "/home/ubuntu/anaconda/lib/python2.7/SocketServer.py", line 716, in finish         self.wfile.close()       File "/home/ubuntu/anaconda/lib/python2.7/socket.py", line 283, in close         self.flush()       File "/home/ubuntu/anaconda/lib/python2.7/socket.py", line 307, in flush         self._sock.sendall(view[write_offset:write_offset+buffer_size])     error: [Errno 32] Broken pipe     xxx.xxx.xxx.xxx - - [28/Oct/2015 05:09:04] code 400, message Bad request syntax ('\x05\x01\x00')     xxx.xxx.xxx.xxx - - [28/Oct/2015 05:09:04] " " 400 -     Traceback (most recent call last):       File "/home/ubuntu/anaconda/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock         self.process_request(request, client_address)       File "/home/ubuntu/anaconda/lib/python2.7/SocketServer.py", line 321, in process_request         self.finish_request(request, client_address)       File "/home/ubuntu/anaconda/lib/python2.7/SocketServer.py", line 334, in finish_request         self.RequestHandlerClass(request, client_address, self)       File "/home/ubuntu/anaconda/lib/python2.7/SocketServer.py", line 657, in __init__         self.finish()       File "/home/ubuntu/anaconda/lib/python2.7/SocketServer.py", line 716, in finish         self.wfile.close()       File "/home/ubuntu/anaconda/lib/python2.7/socket.py", line 283, in close         self.flush()       File "/home/ubuntu/anaconda/lib/python2.7/socket.py", line 307, in flush         self._sock.sendall(view[write_offset:write_offset+buffer_size])     error: [Errno 32] Broken pipe [/code]

A temporary solution I have been using is to kill the Python process and reload the webserver but that is only temporary. (nohup python run.py &)

Link to comment
https://www.neowin.net/forum/topic/1277060-flask-web-server-wont-respond/
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.