You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defsse(request: HttpRequest) ->HttpResponseBase:
"""Small demo of the basic idea of SSE without any redis or other complexity"""asyncdefstream(request: HttpRequest) ->AsyncGenerator[str, None]:
try:
counter=0whileTrue:
counter+=1ifcounter!=1:
awaitasyncio.sleep(1.0)
yieldf"data: <div>{counter}</div>\n\n"exceptasyncio.CancelledError:
logger.debug("SSE Client disconnected")
raisereturnStreamingHttpResponse(
streaming_content=stream(request),
content_type="text/event-stream"
)
When I run this code under the Uvicorn ASGI server, after closing the connection, I see "SSE Client disconnected" in my dubug log. However, under Unit, nothing happens, with only in unit log:
It seems that Django does not detect that the connection is closed, and this is only apparent when I restart Unit. In the logs:
2024/12/01 11:02:55 [warn] 34253#34253 [unit] #516: active request on ctx quit
2024/12/01 11:02:55 [warn] 34253#34253 [unit] #404: active request on ctx free
In a production environment when I use Redis, I see many connections with Unit and Redis in the ESTABLISHED state, even though many connections are already closed. This is a problem for me.
What am I doing wrong 🤔 ?
The text was updated successfully, but these errors were encountered:
Hello.
Sorry, I have a question about Django and ASGI. I saw that a similar topic has already been discussed, but I couldn't find a solution for myself.
Unit 1.33
Django 5.1 (support async handling disconnects)
Python 3.11.2
Debian 12
Test Django code:
When I run this code under the Uvicorn ASGI server, after closing the connection, I see
"SSE Client disconnected"
in my dubug log. However, under Unit, nothing happens, with only in unit log:2024/12/01 11:29:31 [info] 40085#40121 *11 writev(44, 2) failed (32: Broken pipe)
It seems that Django does not detect that the connection is closed, and this is only apparent when I restart Unit. In the logs:
In a production environment when I use Redis, I see many connections with Unit and Redis in the ESTABLISHED state, even though many connections are already closed. This is a problem for me.
What am I doing wrong 🤔 ?
The text was updated successfully, but these errors were encountered: