Previously Functioning System Encounters Websocket Connection Failure

Hello Everyone,

I am currently running a Django application within Docker, and I use websockets to connect to the dashboard app for metrics. While everything was functioning correctly when I checked last week, I encountered an issue yesterday where the service connects to the websocket but immediately disconnects.

2024-01-29 16:32:57  WebSocket HANDSHAKING /ws/dashboard/ [172.21.0.1:47114]
2024-01-29 16:32:57  WebSocket HANDSHAKING /ws/dashboard/ [172.21.0.1:47114]
2024-01-29 16:33:00  WebSocket DISCONNECT /ws/dashboard/ [172.21.0.1:47098]
2024-01-29 16:33:00  WebSocket DISCONNECT /ws/dashboard/ [172.21.0.1:47098]

ASGI

os.environ.setdefault("DJANGO_SETTINGS_MODULE",
                      "cartonprintingsystem.settings")

django_asgi_app = get_asgi_application()


application = ProtocolTypeRouter(
    {
        "http": django_asgi_app,
        "websocket": AllowedHostsOriginValidator(
            AuthMiddlewareStack(
                URLRouter(dashboard.routing.websocket_urlpatterns))
        ),
    }
)

Routing

from django.urls import re_path

from .consumers import DashboardConsumer

websocket_urlpatterns = [
    # re_path(r"ws/dashboard/(?P<room_name>\w+)/$", DashboardConsumer.as_asgi()),
    re_path(r"ws/dashboard", DashboardConsumer.as_asgi()),
]

I just want to know what is causing this issue and how can i resolve it.

Start with all the fundamentals here.

Look at all applicable log files for more information about what may be happening.

Look to see what may have changed in the environment - both inside and outside the application itself.

Look to see if there were any components upgraded.

Basically, treat this as any other system-level error. You need to gather as much information as possible from all available sources to try and identify the cause.

Yeah i followed the Chat tutorial(channels) in django from scratch and implemented again.
It is working.