I have an app deployed on Google App Engine which every couple of days is sending me an error email:
Internal Server Error: /
ConnectionError at /
('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
I am aware that this has been discussed in various places before, but the discussed solutions are so varied, and this error is so sporadic, that it is becoming difficult to resolve.
Django version is 3.1.4 and Python 3.7.9.
Here are a few things I’ve noticed:
- It only seems to occur on the root page (‘/’).
- The user agent seems to be a web crawler.
- I can’t trigger the error myself, nor have I seen another real user trigger it.
- The stack trace is always:
Traceback (most recent call last):
File “/env/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 677, in urlopen
chunked=chunked,
File “/env/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 381, in _make_request
self._validate_conn(conn)
File “/env/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 978, in validate_conn
conn.connect()
File “/env/lib/python3.7/site-packages/urllib3/connection.py”, line 371, in connect
ssl_context=context,
File "/env/lib/python3.7/site-packages/urllib3/util/ssl.py", line 384, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File “/opt/python3.7/lib/python3.7/ssl.py”, line 423, in wrap_socket
session=session
File “/opt/python3.7/lib/python3.7/ssl.py”, line 870, in _create
self.do_handshake()
File “/opt/python3.7/lib/python3.7/ssl.py”, line 1139, in do_handshake
self._sslobj.do_handshake()During handling of the above exception ([Errno 104] Connection reset by peer), another exception occurred:
File “/env/lib/python3.7/site-packages/requests/adapters.py”, line 449, in send
timeout=timeout
File “/env/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 727, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File “/env/lib/python3.7/site-packages/urllib3/util/retry.py”, line 403, in increment
raise six.reraise(type(error), error, _stacktrace)
File “/env/lib/python3.7/site-packages/urllib3/packages/six.py”, line 734, in reraise
raise value.with_traceback(tb)
File “/env/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 677, in urlopen
chunked=chunked,
File “/env/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 381, in _make_request
self._validate_conn(conn)
File “/env/lib/python3.7/site-packages/urllib3/connectionpool.py”, line 978, in validate_conn
conn.connect()
File “/env/lib/python3.7/site-packages/urllib3/connection.py”, line 371, in connect
ssl_context=context,
File "/env/lib/python3.7/site-packages/urllib3/util/ssl.py", line 384, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File “/opt/python3.7/lib/python3.7/ssl.py”, line 423, in wrap_socket
session=session
File “/opt/python3.7/lib/python3.7/ssl.py”, line 870, in _create
self.do_handshake()
File “/opt/python3.7/lib/python3.7/ssl.py”, line 1139, in do_handshake
self._sslobj.do_handshake()During handling of the above exception ((‘Connection aborted.’, ConnectionResetError(104, ‘Connection reset by peer’))), another exception occurred:
File “/env/lib/python3.7/site-packages/django/core/handlers/exception.py”, line 47, in inner
response = get_response(request)
File “/env/lib/python3.7/site-packages/django/core/handlers/base.py”, line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/opt/python3.7/lib/python3.7/contextlib.py”, line 74, in inner
return func(*args, **kwds)
File “/home/vmagent/app/shop/views.py”, line 48, in index
tweets = twitter_client.timeline(requested_timeline)
File “/home/vmagent/app/shop/twitter.py”, line 37, in timeline
user_id = self.get_user(user)
File “/home/vmagent/app/shop/twitter.py”, line 31, in get_user
response = requests.get(url, headers=self.headers)
File “/env/lib/python3.7/site-packages/requests/api.py”, line 76, in get
return request(‘get’, url, params=params, **kwargs)
File “/env/lib/python3.7/site-packages/requests/api.py”, line 61, in request
return session.request(method=method, url=url, **kwargs)
File “/env/lib/python3.7/site-packages/requests/sessions.py”, line 530, in request
resp = self.send(prep, **send_kwargs)
File “/env/lib/python3.7/site-packages/requests/sessions.py”, line 643, in send
r = adapter.send(request, **kwargs)
File “/env/lib/python3.7/site-packages/requests/adapters.py”, line 498, in send
raise ConnectionError(err, request=request)
I’m thinking that maybe something is reloading on the server when a web crawler visits the page. Is there anything I should take a closer look at or can I filter this error?