After working for a while start getting `Exception inside application: No route found for path`
karatemir opened this issue · comments
Hi there,
I have a channels application where I read sensor measurements/results from a redis-server and push them to websockets via channels using a management command (similar to this PyCon talk and its related github repo). The data-flow is fairly rapid, each ~40ms I read vectors of size 1000. Things work great but sometimes after working for a while I start getting Exception inside application: No route found for path
error. Specifically I get the following:
WebSocket HANDSHAKING /ws/undefined/ [127.0.0.1:41410]
Exception inside application: No route found for path 'ws/undefined/'.
Traceback (most recent call last):
File "/venv/lib/python3.8/site-packages/channels/staticfiles.py", line 44, in __call__
return await self.application(scope, receive, send)
File "/venv/lib/python3.8/site-packages/channels/routing.py", line 71, in __call__
return await application(scope, receive, send)
File "/venv/lib/python3.8/site-packages/channels/sessions.py", line 47, in __call__
return await self.inner(dict(scope, cookies=cookies), receive, send)
File "/venv/lib/python3.8/site-packages/channels/sessions.py", line 263, in __call__
return await self.inner(wrapper.scope, receive, wrapper.send)
File "/venv/lib/python3.8/site-packages/channels/auth.py", line 185, in __call__
return await super().__call__(scope, receive, send)
File "/venv/lib/python3.8/site-packages/channels/middleware.py", line 26, in __call__
return await self.inner(scope, receive, send)
File "/venv/lib/python3.8/site-packages/channels/routing.py", line 168, in __call__
raise ValueError("No route found for path %r." % path)
ValueError: No route found for path 'ws/undefined/'.
WebSocket DISCONNECT /ws/undefined/ [127.0.0.1:41410]
After this error, restarting the django development server doesn't help, however if I immediately change to a different port to run runserver
things work well without any change. Also after 15-ish minutes, if I go back to the old port things seem to be working fine as well.
It looks like I somehow deplete some available websocket resources/ports but I am not sure. I also came across this issue , which feels similar.
I am on Ubuntu 20.04 and use:
Python 3.8.10
django 3.2
channels 3.0.4
channels_redis 3.3.1
asgiref 3.3.4
Redis server v=6.2.6
Thanks.
Does your application have a path for 'ws/undefined/'
?
I'm guessing not ... ?
If not, it seems to me that the issue is in your JS code ... undefined
is a JS concept ... I would guess your JS code is constructing the path incorrectly using a variable that is, well, undefined.
@acu192, no I don't have a path for ws/undefined/
.
You might be right, I have to dig into the JS code. I am passing the channel name from settings.py using a django template as in here to the js script.
from django import template
from django.conf import settings
register = template.Library()
ALLOWABLE_VALUES = ("CONSTANT_NAME_1", "CONSTANT_NAME_2",)
# settings value
@register.simple_tag
def settings_value(name):
if name in ALLOWABLE_VALUES:
return getattr(settings, name, '')
return ''
The problem is though, things work fine with no errors but after a while errors starts happening and I can't somehow get rid of the no route for ws/undefined
error. However, changing the port number for runserver
immediately does the job. That's why I thought it might have something to do with channels-side but looks like I might need to investigate this further. Thanks for your answer!