API crash on the activity endpoint
Steps to reproduce
- Listen to music
- See activity background websocket calls resulting in 500 errors
What happens?
The API crashes systematically on this specific call.
What is expected?
The API call completes successfully.
Context
Funkwhale version(s) affected: 0.20, custom setup based on the funkwhale/funkwhale
docker image, in a Kubernetes cluster.
Browser is the latest Firefox in Debian unstable (69.0).
The HTTP API call triggering the crash
10.2.1.32 - - [26/Oct/2019:13:38:46 +0000] "GET /api/v1/activity?token={redacted} HTTP/1.1" 500 21 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0" "10.2.0.0"
The API stack trace:
[2019-10-26 13:38:31 +0000] [12] [ERROR] Exception in ASGI application
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "/usr/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 223, in create_cursor
cursor = self.connection.cursor()
psycopg2.InterfaceError: connection already closed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 152, in run_asgi
result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
File "/usr/lib/python3.6/site-packages/uvicorn/middleware/asgi2.py", line 6, in __call__
instance = self.app(scope)
File "/usr/lib/python3.6/site-packages/channels/routing.py", line 58, in __call__
return self.application_mapping[scope["type"]](scope)
File "/app/funkwhale_api/common/auth.py", line 34, in __call__
user, token = auth.authenticate(scope)
File "/usr/lib/python3.6/site-packages/rest_framework_jwt/authentication.py", line 33, in authenticate
payload = jwt_decode_handler(jwt_value)
File "/usr/lib/python3.6/site-packages/rest_framework_jwt/utils.py", line 105, in jwt_decode_handler
secret_key = jwt_get_secret_key(unverified_payload)
File "/usr/lib/python3.6/site-packages/rest_framework_jwt/utils.py", line 26, in jwt_get_secret_key
user = User.objects.get(pk=payload.get('user_id'))
File "/usr/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 402, in get
num = len(clone)
File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 256, in __len__
self._fetch_all()
File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 55, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/usr/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1098, in execute_sql
cursor = self.connection.cursor()
File "/usr/lib/python3.6/site-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/usr/lib/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "/usr/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/lib/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
return self._prepare_cursor(self.create_cursor(name))
File "/usr/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 223, in create_cursor
cursor = self.connection.cursor()
django.db.utils.InterfaceError: connection already closed