Issue 1:
I have the following Flask app running in a Stage server, and I realized that some requests were affecting its operation, causing Tracebacks and with this, the Flask app was still running as a process, but not answering any sort of request, neither giving a kind of Internal Server Error (5xx).

Here is my code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

from flask import Flask, jsonify
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False

limiter = Limiter (
app,
key_func=get_remote_address,
global_limits=["180 per day","30 per hour"]
)

@app.after_request
def server_response(response):
response.headers["Server"] = "WS"
return response

@app.route('/json')
def f_json():

d = { "result":[
{"id":"1","name":"John","email":"john-flask@gmail.com"},
{"id":"2","name":"NIkolas","email":"nikolas-flask@gmail.com"},
{"id":"3","name":"Samanta","email":"samanta-flask@gmail.com"}
]}
return jsonify(d)

if __name__ == '__main__':
app.run(host='0.0.0.0', port=80, debug=True)

Here is what I found in the debug, which caused the Traceback (and Flask was still running, but not answering any request).

191.96.249.231 - - [30/Jun/2016 19:11:47] "GET /plugins/system/plugin_googlemap2/plugin_googlemap2_proxy.php?url=http://191.96.249.231/shodanhq HTTP/1.0" 404 -
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 659, in inner
srv.serve_forever()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 499, in serve_forever
HTTPServer.serve_forever(self)
File "/usr/lib/python2.7/SocketServer.py", line 238, in serve_forever
self._handle_request_noblock()
File "/usr/lib/python2.7/SocketServer.py", line 297, in _handle_request_noblock
self.handle_error(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__
self.handle()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 216, 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 251, in handle_one_request
return self.run_wsgi()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 193, in run_wsgi
execute(self.server.app)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 184, in execute
write(data)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 149, in write
self.send_response(int(code), msg)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 260, in send_response
self.wfile.write(hdr.encode('ascii'))
IOError: [Errno 32] Broken pipe

It also happened in this situation, but I believe that "Connection Reset by Peer" was already addressed and fixed, (miguelgrinberg/Flask-SocketIO#184), but I believe it is worth to be mentioned regarding the data which was requested to Flask (it really caught my attention...)

169.229.3.91 - - [29/Jun/2016 09:12:37] "0<B0>$e<AE>x<D4>^?<AB><AC>1<E8><CF>Oۚ<9C>^K@<BA><D2><FE><D4>q_^]i=AS%<D7>`I<CA>`<8F><C8>6<E5>E^SX)B<A5>-{^RoK^BT<E4><82>}O'\<BB><8B><E4>a<86>" 400 -
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 659, in inner
srv.serve_forever()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 499, in serve_forever
HTTPServer.serve_forever(self)
File "/usr/lib/python2.7/SocketServer.py", line 238, in serve_forever
self._handle_request_noblock()
File "/usr/lib/python2.7/SocketServer.py", line 297, in _handle_request_noblock
self.handle_error(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 649, in __init__
self.handle()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 216, 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 247, in handle_one_request
self.raw_requestline = self.rfile.readline()
IOError: [Errno 104] Connection reset by peer

I believe that it would be interesting to have a kind of "recovery" for Flask, or a better way to deal with it, without staying hanged..

Issue 2:
I have a Werkzeug server running behind NGINX. When a client disconnects while waiting for the Werkzeug server to respond, NGINX closes the pipe to Werkzeug. When the python program writes the response to Werkzeug, the following exception occurs and Werkzeug crashes:

Traceback (most recent call last):

File "server.py", line 81, in

app.run(host=args.host, port=args.port, debug=False)

File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 843, in run

run_simple(host, port, self, **options)

File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 694, in run_simple

inner()

File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 659, in inner

srv.serve_forever()

File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 499, in serve_forever

HTTPServer.serve_forever(self)

File "/usr/lib/python2.7/SocketServer.py", line 238, in serve_forever

self._handle_request_noblock()

File "/usr/lib/python2.7/SocketServer.py", line 297, in _handle_request_noblock

self.handle_error(request, client_address)

File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock

self.process_request(request, client_address)

File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request

self.finish_request(request, client_address)

File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request

self.RequestHandlerClass(request, client_address, self)

File "/usr/lib/python2.7/SocketServer.py", line 651, in init

self.finish()

File "/usr/lib/python2.7/SocketServer.py", line 710, in finish

self.wfile.close()

File "/usr/lib/python2.7/socket.py", line 279, in close

self.flush()

File "/usr/lib/python2.7/socket.py", line 303, in flush

self._sock.sendall(view[write_offset:write_offset+buffer_size])

socket.error: [Errno 32] Broken pipe

Is there some configuration option I'm missing to keep it from crashing? Normally all exceptions are caught and a 500 error returned, with the server remaining alive.