I'm running a Django Rest Framework app on Ubuntu 14.04.3 with Nginx 1.4.6, with a Google Cloud SQL backend. I'm using Django 1.7 and Django Rest Framework 3.1.2.
Both the site and the Google Cloud SQL connection are running over SSL.
What I'm running into is that about one in every 75-100 requests returns a 500 error. It's very intermittent. If, for example, a request to get the values for a dropdown list in a popup control fails once, if I close and re-open the popup it will work the second time.
It affects calls to random endpoints - I haven't been able to detect a pattern.
The Django error log shows:
AttributeError: 'SessionStore' object has no attribute '_session_cache'
Based on this question I've verified that the database does have a django_session table and django.contrib.sessions.middleware.SessionMiddleware
is in my settings.py
file.
At the bottom of the error log details, I see:
django.db.utils.OperationalError: (2026, 'SSL connection error: unknown error number')
I've read this question, but it's unclear to me if this is the same thing. My setup is much more vanilla than what's described there (no load balancing, no celery) and there doesn't appear to be an official issue opened up by the Google Cloud SQL team on this issue (I haven't been able to find it, anyway).
The full stack trace for one of the errors:
Internal Server Error: /api/v1/ref/contact-types/
Traceback (most recent call last):
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/contrib/sessions/backends/base.py", line 170, in _get_session
return self._session_cache
AttributeError: 'SessionStore' object has no attribute '_session_cache'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/backends/__init__.py", line 133, in ensure_connection
self.connect()
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/backends/__init__.py", line 122, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/backends/mysql/base.py", line 471, in get_new_connection
conn = Database.connect(**conn_params)
File "/home/foo/bar/venv/lib/python3.4/site-packages/MySQLdb/__init__.py", line
81, in Connect
return Connection(*args, **kwargs)
File "/home/foo/bar/venv/lib/python3.4/site-packages/MySQLdb/connections.py",
line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2026, 'SSL connection error: unknown error number')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/core/handlers/base.py", line 87, in get_response
response = middleware_method(request)
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/contrib/auth/middleware.py", line 34, in process_request
if user and hasattr(user, 'get_session_auth_hash'):
File "/home/foo/bar/venv/lib/python3.4/site-packages/django/utils/functional.py",
line 224, in inner
self._setup()
File "/home/foo/bar/venv/lib/python3.4/site-packages/django/utils/functional.py",
line 357, in _setup
self._wrapped = self._setupfunc()
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/contrib/auth/middleware.py", line 23, in <lambda>
request.user = SimpleLazyObject(lambda: get_user(request))
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/contrib/auth/middleware.py", line 11, in get_user
request._cached_user = auth.get_user(request)
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/contrib/auth/__init__.py", line 151, in get_user
user_id = request.session[SESSION_KEY]
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/contrib/sessions/backends/base.py", line 49, in __getitem__
return self._session[key]
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/contrib/sessions/backends/base.py", line 175, in _get_session
self._session_cache = self.load()
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/contrib/sessions/backends/db.py", line 21, in load
expire_date__gt=timezone.now()
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/models/query.py", line 351, in get
num = len(clone)
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/models/query.py", line 122, in __len__
num = len(clone)
self._fetch_all()
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/models/query.py", line 966, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/models/query.py", line 265, in iterator
for row in compiler.results_iter():
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/models/sql/compiler.py", line 700, in results_
iter
for rows in self.execute_sql(MULTI):
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/models/sql/compiler.py", line 784, in execute_
sql
cursor = self.connection.cursor()
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/backends/__init__.py", line 167, in cursor
cursor = utils.CursorWrapper(self._cursor(), self)
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/backends/__init__.py", line 138, in _cursor
self.ensure_connection()
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/backends/__init__.py", line 133, in ensure_con
nection
self.connect()
File "/home/foo/bar/venv/lib/python3.4/site-packages/django/db/utils.py", line 94,
in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/foo/bar/venv/lib/python3.4/site-packages/django/utils/six.py", line
549, in reraise
raise value.with_traceback(tb)
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/backends/__init__.py", line 133, in ensure_con
nection
self.connect()
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/backends/__init__.py", line 122, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/foo/bar/venv/lib/python3.4/site-
packages/django/db/backends/mysql/base.py", line 471, in get_new_
connection
conn = Database.connect(**conn_params)
File "/home/foo/bar/venv/lib/python3.4/site-packages/MySQLdb/__init__.py", line
81, in Connect
return Connection(*args, **kwargs)
File "/home/foo/bar/venv/lib/python3.4/site-packages/MySQLdb/connections.py",
line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2026, 'SSL connection error: unknown error number')