chevron-up bell reply instagram twitter2 feed3 finder search-25px-p0

Flask WSGI server error: code 400, message Bad request version (‘\xefg#\x00&\xc0,\xc0+\xc0$\xc0#\xc0’)


When I went to office this morning, I was told one of company's website is not running properly. To be more specific, the whole web will be frozen every time 10 mins after a restart. The web was developed by myself and it was using Flask, with a SSL certificate in it.

As a first glance of the log: - - [12/Jun/2017 14:30:26] code 400, message Bad request version ('\xefg#\x00&\xc0,\xc0+\xc0$\xc0#\xc0') - - [12/Jun/2017 14:30:26] "^V^C^A^B^@^A^@^A?^C^C$E???GiVCE???d^]?9????<1d>?l?????^C N^??^U?ǛAf?E1^???^EV{c?^HW?A.?T^N^K?g#^@&?,?+?$?#?" 400 -
Traceback (most recent call last):
  File "/usr/lib64/python2.7/", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib64/python2.7/", line 321, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib64/python2.7/", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib64/python2.7/", line 651, in __init__
  File "/usr/lib64/python2.7/", line 710, in finish
  File "/usr/lib64/python2.7/", line 279, in close
  File "/usr/lib64/python2.7/", line 303, in flush
  File "/usr/lib64/python2.7/", line 750, in sendall
    return socket.sendall(self, data, flags)
  File "/usr/lib64/python2.7/", line 224, in meth
    return getattr(self._sock,name)(*args)

I thought it might be a SSL certificate issue, which might not be configured correctly. As I simply deploy the code from git server, and not regenerate the SSL keys. After redo the key, the web is still the same. This time, I found a lot of TCP connections "Close Wait":

As we known, when a TCP connection is in "Close Wait" status, which means this connection is not fully released, and waiting for a close by the web server. So I go to the Flask server setting file.

                    Server(host='', port=8889, use_debugger=False, ssl_context=context_prod))

Wait, a web server must be multi-threading, instead of waiting for a single thread to do all the jobs, so when I add threaded=True and restart the web server, the issue disappeared.

                    Server(host='', port=8889, threaded=True, use_debugger=False, ssl_context=context_prod))


Make Your Comments