We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error handling all requests on master - attempt to read attribute of NoneType
I'm trying to run Gunicorn on the master branch (latest commit is 4c601ce447fafbeed27f0f0a238e0e48c928b6f9). But every incoming request generates this error:

```
[2014-10-27 20:36:55 +0000] [22663] [ERROR] Error handling request
Traceback (most recent call last):
  File "/mnt/runscope/.virtualenvs/embedcurl/src/gunicorn/gunicorn/workers/async.py", line 41, in handle
    proxy_protocol_info = req.proxy_protocol_info
AttributeError: 'NoneType' object has no attribute 'proxy_protocol_info'
```

This is my gunicorn command line:

```
/usr/local/runscope/.virtualenvs/embedcurl/bin/gunicorn \
    --name embedcurl -k gevent --workers=2 --bind 0.0.0.0:3002 \
    --error-logfile /var/log/runscope/embedcurl.error.log \
    --access-logfile /var/log/runscope/embedcurl.access.log \
    --access-logformat '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s %(T)s %(D)s "%(f)s" "%(a)s"' \
    --max-requests 50000 \
    --max-requests-jitter 500 \
    --statsd-prefix service.embedcurl.test004. \
    -D "embedcurl:app" --pid /var/run/embedcurl.pid
```

I think the problem comes from commit adf353f213d12994cc36ecbbcb6a084baf1fda12. See the file https://github.com/benoitc/gunicorn/blob/adf353f213d12994cc36ecbbcb6a084baf1fda12/gunicorn/workers/async.py -- line 41 reads from `req.proxy_protocol_info` but `req` is always None when that line runs. I'm not familiar with `proxy_protocol_info` myself so I'm not quite sure what the fix is.

Error handling all requests on master - attempt to read attribute of NoneType
I'm trying to run Gunicorn on the master branch (latest commit is 4c601ce447fafbeed27f0f0a238e0e48c928b6f9). But every incoming request generates this error:

```
[2014-10-27 20:36:55 +0000] [22663] [ERROR] Error handling request
Traceback (most recent call last):
  File "/mnt/runscope/.virtualenvs/embedcurl/src/gunicorn/gunicorn/workers/async.py", line 41, in handle
    proxy_protocol_info = req.proxy_protocol_info
AttributeError: 'NoneType' object has no attribute 'proxy_protocol_info'
```

This is my gunicorn command line:

```
/usr/local/runscope/.virtualenvs/embedcurl/bin/gunicorn \
    --name embedcurl -k gevent --workers=2 --bind 0.0.0.0:3002 \
    --error-logfile /var/log/runscope/embedcurl.error.log \
    --access-logfile /var/log/runscope/embedcurl.access.log \
    --access-logformat '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s %(T)s %(D)s "%(f)s" "%(a)s"' \
    --max-requests 50000 \
    --max-requests-jitter 500 \
    --statsd-prefix service.embedcurl.test004. \
    -D "embedcurl:app" --pid /var/run/embedcurl.pid
```

I think the problem comes from commit adf353f213d12994cc36ecbbcb6a084baf1fda12. See the file https://github.com/benoitc/gunicorn/blob/adf353f213d12994cc36ecbbcb6a084baf1fda12/gunicorn/workers/async.py -- line 41 reads from `req.proxy_protocol_info` but `req` is always None when that line runs. I'm not familiar with `proxy_protocol_info` myself so I'm not quite sure what the fix is.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `gunicorn/workers/async.py`
Content:
```
1 # -*- coding: utf-8 -
2 #
3 # This file is part of gunicorn released under the MIT license.
4 # See the NOTICE for more information.
5 
6 from datetime import datetime
7 import errno
8 import socket
9 import ssl
10 import sys
11 
12 import gunicorn.http as http
13 import gunicorn.http.wsgi as wsgi
14 import gunicorn.util as util
15 import gunicorn.workers.base as base
16 from gunicorn import six
17 
18 ALREADY_HANDLED = object()
19 
20 
21 class AsyncWorker(base.Worker):
22 
23     def __init__(self, *args, **kwargs):
24         super(AsyncWorker, self).__init__(*args, **kwargs)
25         self.worker_connections = self.cfg.worker_connections
26 
27     def timeout_ctx(self):
28         raise NotImplementedError()
29 
30     def handle(self, listener, client, addr):
31         req = None
32         try:
33             parser = http.RequestParser(self.cfg, client)
34             try:
35                 listener_name = listener.getsockname()
36                 if not self.cfg.keepalive:
37                     req = six.next(parser)
38                     self.handle_request(listener_name, req, client, addr)
39                 else:
40                     # keepalive loop
41                     proxy_protocol_info = req.proxy_protocol_info
42                     while True:
43                         req = None
44                         with self.timeout_ctx():
45                             req = six.next(parser)
46                         if not req:
47                             break
48                         req.proxy_protocol_info = proxy_protocol_info
49                         self.handle_request(listener_name, req, client, addr)
50             except http.errors.NoMoreData as e:
51                 self.log.debug("Ignored premature client disconnection. %s", e)
52             except StopIteration as e:
53                 self.log.debug("Closing connection. %s", e)
54             except ssl.SSLError:
55                 exc_info = sys.exc_info()
56                 # pass to next try-except level
57                 six.reraise(exc_info[0], exc_info[1], exc_info[2])
58             except socket.error:
59                 exc_info = sys.exc_info()
60                 # pass to next try-except level
61                 six.reraise(exc_info[0], exc_info[1], exc_info[2])
62             except Exception as e:
63                 self.handle_error(req, client, addr, e)
64         except ssl.SSLError as e:
65             if e.args[0] == ssl.SSL_ERROR_EOF:
66                 self.log.debug("ssl connection closed")
67                 client.close()
68             else:
69                 self.log.debug("Error processing SSL request.")
70                 self.handle_error(req, client, addr, e)
71         except socket.error as e:
72             if e.args[0] not in (errno.EPIPE, errno.ECONNRESET):
73                 self.log.exception("Socket error processing request.")
74             else:
75                 if e.args[0] == errno.ECONNRESET:
76                     self.log.debug("Ignoring connection reset")
77                 else:
78                     self.log.debug("Ignoring EPIPE")
79         except Exception as e:
80             self.handle_error(req, client, addr, e)
81         finally:
82             util.close(client)
83 
84     def handle_request(self, listener_name, req, sock, addr):
85         request_start = datetime.now()
86         environ = {}
87         resp = None
88         try:
89             self.cfg.pre_request(self, req)
90             resp, environ = wsgi.create(req, sock, addr,
91                     listener_name, self.cfg)
92             environ["wsgi.multithread"] = True
93             self.nr += 1
94             if self.alive and self.nr >= self.max_requests:
95                 self.log.info("Autorestarting worker after current request.")
96                 resp.force_close()
97                 self.alive = False
98 
99             if not self.cfg.keepalive:
100                 resp.force_close()
101 
102             respiter = self.wsgi(environ, resp.start_response)
103             if respiter == ALREADY_HANDLED:
104                 return False
105             try:
106                 if isinstance(respiter, environ['wsgi.file_wrapper']):
107                     resp.write_file(respiter)
108                 else:
109                     for item in respiter:
110                         resp.write(item)
111                 resp.close()
112                 request_time = datetime.now() - request_start
113                 self.log.access(resp, req, environ, request_time)
114             finally:
115                 if hasattr(respiter, "close"):
116                     respiter.close()
117             if resp.should_close():
118                 raise StopIteration()
119         except StopIteration:
120             raise
121         except Exception:
122             if resp and resp.headers_sent:
123                 # If the requests have already been sent, we should close the
124                 # connection to indicate the error.
125                 self.log.exception("Error handling request")
126                 try:
127                     sock.shutdown(socket.SHUT_RDWR)
128                     sock.close()
129                 except socket.error:
130                     pass
131                 raise StopIteration()
132             raise
133         finally:
134             try:
135                 self.cfg.post_request(self, req, environ, resp)
136             except Exception:
137                 self.log.exception("Exception in post_request hook")
138         return True
139
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py
--- a/gunicorn/workers/async.py
+++ b/gunicorn/workers/async.py
@@ -38,14 +38,17 @@
                     self.handle_request(listener_name, req, client, addr)
                 else:
                     # keepalive loop
-                    proxy_protocol_info = req.proxy_protocol_info
+                    proxy_protocol_info = {}
                     while True:
                         req = None
                         with self.timeout_ctx():
                             req = six.next(parser)
                         if not req:
                             break
-                        req.proxy_protocol_info = proxy_protocol_info
+                        if req.proxy_protocol_info:
+                            proxy_protocol_info = req.proxy_protocol_info
+                        else:
+                            req.proxy_protocol_info = proxy_protocol_info
                         self.handle_request(listener_name, req, client, addr)
             except http.errors.NoMoreData as e:
                 self.log.debug("Ignored premature client disconnection. %s", e)

{"golden_diff": "diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py\n--- a/gunicorn/workers/async.py\n+++ b/gunicorn/workers/async.py\n@@ -38,14 +38,17 @@\n                     self.handle_request(listener_name, req, client, addr)\n                 else:\n                     # keepalive loop\n-                    proxy_protocol_info = req.proxy_protocol_info\n+                    proxy_protocol_info = {}\n                     while True:\n                         req = None\n                         with self.timeout_ctx():\n                             req = six.next(parser)\n                         if not req:\n                             break\n-                        req.proxy_protocol_info = proxy_protocol_info\n+                        if req.proxy_protocol_info:\n+                            proxy_protocol_info = req.proxy_protocol_info\n+                        else:\n+                            req.proxy_protocol_info = proxy_protocol_info\n                         self.handle_request(listener_name, req, client, addr)\n             except http.errors.NoMoreData as e:\n                 self.log.debug(\"Ignored premature client disconnection. %s\", e)\n", "issue": "Error handling all requests on master - attempt to read attribute of NoneType\nI'm trying to run Gunicorn on the master branch (latest commit is 4c601ce447fafbeed27f0f0a238e0e48c928b6f9). But every incoming request generates this error:\n\n```\n[2014-10-27 20:36:55 +0000] [22663] [ERROR] Error handling request\nTraceback (most recent call last):\n  File \"/mnt/runscope/.virtualenvs/embedcurl/src/gunicorn/gunicorn/workers/async.py\", line 41, in handle\n    proxy_protocol_info = req.proxy_protocol_info\nAttributeError: 'NoneType' object has no attribute 'proxy_protocol_info'\n```\n\nThis is my gunicorn command line:\n\n```\n/usr/local/runscope/.virtualenvs/embedcurl/bin/gunicorn \\\n    --name embedcurl -k gevent --workers=2 --bind 0.0.0.0:3002 \\\n    --error-logfile /var/log/runscope/embedcurl.error.log \\\n    --access-logfile /var/log/runscope/embedcurl.access.log \\\n    --access-logformat '%(h)s %(l)s %(u)s %(t)s \"%(r)s\" %(s)s %(b)s %(T)s %(D)s \"%(f)s\" \"%(a)s\"' \\\n    --max-requests 50000 \\\n    --max-requests-jitter 500 \\\n    --statsd-prefix service.embedcurl.test004. \\\n    -D \"embedcurl:app\" --pid /var/run/embedcurl.pid\n```\n\nI think the problem comes from commit adf353f213d12994cc36ecbbcb6a084baf1fda12. See the file https://github.com/benoitc/gunicorn/blob/adf353f213d12994cc36ecbbcb6a084baf1fda12/gunicorn/workers/async.py -- line 41 reads from `req.proxy_protocol_info` but `req` is always None when that line runs. I'm not familiar with `proxy_protocol_info` myself so I'm not quite sure what the fix is.\n\nError handling all requests on master - attempt to read attribute of NoneType\nI'm trying to run Gunicorn on the master branch (latest commit is 4c601ce447fafbeed27f0f0a238e0e48c928b6f9). But every incoming request generates this error:\n\n```\n[2014-10-27 20:36:55 +0000] [22663] [ERROR] Error handling request\nTraceback (most recent call last):\n  File \"/mnt/runscope/.virtualenvs/embedcurl/src/gunicorn/gunicorn/workers/async.py\", line 41, in handle\n    proxy_protocol_info = req.proxy_protocol_info\nAttributeError: 'NoneType' object has no attribute 'proxy_protocol_info'\n```\n\nThis is my gunicorn command line:\n\n```\n/usr/local/runscope/.virtualenvs/embedcurl/bin/gunicorn \\\n    --name embedcurl -k gevent --workers=2 --bind 0.0.0.0:3002 \\\n    --error-logfile /var/log/runscope/embedcurl.error.log \\\n    --access-logfile /var/log/runscope/embedcurl.access.log \\\n    --access-logformat '%(h)s %(l)s %(u)s %(t)s \"%(r)s\" %(s)s %(b)s %(T)s %(D)s \"%(f)s\" \"%(a)s\"' \\\n    --max-requests 50000 \\\n    --max-requests-jitter 500 \\\n    --statsd-prefix service.embedcurl.test004. \\\n    -D \"embedcurl:app\" --pid /var/run/embedcurl.pid\n```\n\nI think the problem comes from commit adf353f213d12994cc36ecbbcb6a084baf1fda12. See the file https://github.com/benoitc/gunicorn/blob/adf353f213d12994cc36ecbbcb6a084baf1fda12/gunicorn/workers/async.py -- line 41 reads from `req.proxy_protocol_info` but `req` is always None when that line runs. I'm not familiar with `proxy_protocol_info` myself so I'm not quite sure what the fix is.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -\n#\n# This file is part of gunicorn released under the MIT license.\n# See the NOTICE for more information.\n\nfrom datetime import datetime\nimport errno\nimport socket\nimport ssl\nimport sys\n\nimport gunicorn.http as http\nimport gunicorn.http.wsgi as wsgi\nimport gunicorn.util as util\nimport gunicorn.workers.base as base\nfrom gunicorn import six\n\nALREADY_HANDLED = object()\n\n\nclass AsyncWorker(base.Worker):\n\n    def __init__(self, *args, **kwargs):\n        super(AsyncWorker, self).__init__(*args, **kwargs)\n        self.worker_connections = self.cfg.worker_connections\n\n    def timeout_ctx(self):\n        raise NotImplementedError()\n\n    def handle(self, listener, client, addr):\n        req = None\n        try:\n            parser = http.RequestParser(self.cfg, client)\n            try:\n                listener_name = listener.getsockname()\n                if not self.cfg.keepalive:\n                    req = six.next(parser)\n                    self.handle_request(listener_name, req, client, addr)\n                else:\n                    # keepalive loop\n                    proxy_protocol_info = req.proxy_protocol_info\n                    while True:\n                        req = None\n                        with self.timeout_ctx():\n                            req = six.next(parser)\n                        if not req:\n                            break\n                        req.proxy_protocol_info = proxy_protocol_info\n                        self.handle_request(listener_name, req, client, addr)\n            except http.errors.NoMoreData as e:\n                self.log.debug(\"Ignored premature client disconnection. %s\", e)\n            except StopIteration as e:\n                self.log.debug(\"Closing connection. %s\", e)\n            except ssl.SSLError:\n                exc_info = sys.exc_info()\n                # pass to next try-except level\n                six.reraise(exc_info[0], exc_info[1], exc_info[2])\n            except socket.error:\n                exc_info = sys.exc_info()\n                # pass to next try-except level\n                six.reraise(exc_info[0], exc_info[1], exc_info[2])\n            except Exception as e:\n                self.handle_error(req, client, addr, e)\n        except ssl.SSLError as e:\n            if e.args[0] == ssl.SSL_ERROR_EOF:\n                self.log.debug(\"ssl connection closed\")\n                client.close()\n            else:\n                self.log.debug(\"Error processing SSL request.\")\n                self.handle_error(req, client, addr, e)\n        except socket.error as e:\n            if e.args[0] not in (errno.EPIPE, errno.ECONNRESET):\n                self.log.exception(\"Socket error processing request.\")\n            else:\n                if e.args[0] == errno.ECONNRESET:\n                    self.log.debug(\"Ignoring connection reset\")\n                else:\n                    self.log.debug(\"Ignoring EPIPE\")\n        except Exception as e:\n            self.handle_error(req, client, addr, e)\n        finally:\n            util.close(client)\n\n    def handle_request(self, listener_name, req, sock, addr):\n        request_start = datetime.now()\n        environ = {}\n        resp = None\n        try:\n            self.cfg.pre_request(self, req)\n            resp, environ = wsgi.create(req, sock, addr,\n                    listener_name, self.cfg)\n            environ[\"wsgi.multithread\"] = True\n            self.nr += 1\n            if self.alive and self.nr >= self.max_requests:\n                self.log.info(\"Autorestarting worker after current request.\")\n                resp.force_close()\n                self.alive = False\n\n            if not self.cfg.keepalive:\n                resp.force_close()\n\n            respiter = self.wsgi(environ, resp.start_response)\n            if respiter == ALREADY_HANDLED:\n                return False\n            try:\n                if isinstance(respiter, environ['wsgi.file_wrapper']):\n                    resp.write_file(respiter)\n                else:\n                    for item in respiter:\n                        resp.write(item)\n                resp.close()\n                request_time = datetime.now() - request_start\n                self.log.access(resp, req, environ, request_time)\n            finally:\n                if hasattr(respiter, \"close\"):\n                    respiter.close()\n            if resp.should_close():\n                raise StopIteration()\n        except StopIteration:\n            raise\n        except Exception:\n            if resp and resp.headers_sent:\n                # If the requests have already been sent, we should close the\n                # connection to indicate the error.\n                self.log.exception(\"Error handling request\")\n                try:\n                    sock.shutdown(socket.SHUT_RDWR)\n                    sock.close()\n                except socket.error:\n                    pass\n                raise StopIteration()\n            raise\n        finally:\n            try:\n                self.cfg.post_request(self, req, environ, resp)\n            except Exception:\n                self.log.exception(\"Exception in post_request hook\")\n        return True\n", "path": "gunicorn/workers/async.py"}], "after_files": [{"content": "# -*- coding: utf-8 -\n#\n# This file is part of gunicorn released under the MIT license.\n# See the NOTICE for more information.\n\nfrom datetime import datetime\nimport errno\nimport socket\nimport ssl\nimport sys\n\nimport gunicorn.http as http\nimport gunicorn.http.wsgi as wsgi\nimport gunicorn.util as util\nimport gunicorn.workers.base as base\nfrom gunicorn import six\n\nALREADY_HANDLED = object()\n\n\nclass AsyncWorker(base.Worker):\n\n    def __init__(self, *args, **kwargs):\n        super(AsyncWorker, self).__init__(*args, **kwargs)\n        self.worker_connections = self.cfg.worker_connections\n\n    def timeout_ctx(self):\n        raise NotImplementedError()\n\n    def handle(self, listener, client, addr):\n        req = None\n        try:\n            parser = http.RequestParser(self.cfg, client)\n            try:\n                listener_name = listener.getsockname()\n                if not self.cfg.keepalive:\n                    req = six.next(parser)\n                    self.handle_request(listener_name, req, client, addr)\n                else:\n                    # keepalive loop\n                    proxy_protocol_info = {}\n                    while True:\n                        req = None\n                        with self.timeout_ctx():\n                            req = six.next(parser)\n                        if not req:\n                            break\n                        if req.proxy_protocol_info:\n                            proxy_protocol_info = req.proxy_protocol_info\n                        else:\n                            req.proxy_protocol_info = proxy_protocol_info\n                        self.handle_request(listener_name, req, client, addr)\n            except http.errors.NoMoreData as e:\n                self.log.debug(\"Ignored premature client disconnection. %s\", e)\n            except StopIteration as e:\n                self.log.debug(\"Closing connection. %s\", e)\n            except ssl.SSLError:\n                exc_info = sys.exc_info()\n                # pass to next try-except level\n                six.reraise(exc_info[0], exc_info[1], exc_info[2])\n            except socket.error:\n                exc_info = sys.exc_info()\n                # pass to next try-except level\n                six.reraise(exc_info[0], exc_info[1], exc_info[2])\n            except Exception as e:\n                self.handle_error(req, client, addr, e)\n        except ssl.SSLError as e:\n            if e.args[0] == ssl.SSL_ERROR_EOF:\n                self.log.debug(\"ssl connection closed\")\n                client.close()\n            else:\n                self.log.debug(\"Error processing SSL request.\")\n                self.handle_error(req, client, addr, e)\n        except socket.error as e:\n            if e.args[0] not in (errno.EPIPE, errno.ECONNRESET):\n                self.log.exception(\"Socket error processing request.\")\n            else:\n                if e.args[0] == errno.ECONNRESET:\n                    self.log.debug(\"Ignoring connection reset\")\n                else:\n                    self.log.debug(\"Ignoring EPIPE\")\n        except Exception as e:\n            self.handle_error(req, client, addr, e)\n        finally:\n            util.close(client)\n\n    def handle_request(self, listener_name, req, sock, addr):\n        request_start = datetime.now()\n        environ = {}\n        resp = None\n        try:\n            self.cfg.pre_request(self, req)\n            resp, environ = wsgi.create(req, sock, addr,\n                    listener_name, self.cfg)\n            environ[\"wsgi.multithread\"] = True\n            self.nr += 1\n            if self.alive and self.nr >= self.max_requests:\n                self.log.info(\"Autorestarting worker after current request.\")\n                resp.force_close()\n                self.alive = False\n\n            if not self.cfg.keepalive:\n                resp.force_close()\n\n            respiter = self.wsgi(environ, resp.start_response)\n            if respiter == ALREADY_HANDLED:\n                return False\n            try:\n                if isinstance(respiter, environ['wsgi.file_wrapper']):\n                    resp.write_file(respiter)\n                else:\n                    for item in respiter:\n                        resp.write(item)\n                resp.close()\n                request_time = datetime.now() - request_start\n                self.log.access(resp, req, environ, request_time)\n            finally:\n                if hasattr(respiter, \"close\"):\n                    respiter.close()\n            if resp.should_close():\n                raise StopIteration()\n        except StopIteration:\n            raise\n        except Exception:\n            if resp and resp.headers_sent:\n                # If the requests have already been sent, we should close the\n                # connection to indicate the error.\n                self.log.exception(\"Error handling request\")\n                try:\n                    sock.shutdown(socket.SHUT_RDWR)\n                    sock.close()\n                except socket.error:\n                    pass\n                raise StopIteration()\n            raise\n        finally:\n            try:\n                self.cfg.post_request(self, req, environ, resp)\n            except Exception:\n                self.log.exception(\"Exception in post_request hook\")\n        return True\n", "path": "gunicorn/workers/async.py"}]}