-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Events Only Sent On Server Exit #57
Comments
Additionally - if I do something like try to close pubcontrol myself. It has no effect, still nothing is sent until the server is restarted or existed. So it looks like this is not related to the |
I just tried the chat example using Django 3.0.3, Daphne 2.5.0, Channels 2.4.0, and Python 3.6.9, and it worked fine. Can you try the chat example the same way, but with your Python 3.7.5? |
Tried the chat example with Python 3.7.5 and its functional (events are received immediately as expected). I've been trying to find the differences between the chat example and mine. The only 2 remaining is that the static files are defined separately (react frontend) and hosted separately as indicated in the first post. With Django providing the backend API server. I've used other SSE libraries with other frameworks though with the same overall setup and never had an issue like this, and again I do receive all of the SSE's.. just when the server restarts. The other difference is that Djoser is used for authentication. It doesn't seem to be interfering though since the client can still connect to the channel and ultimately receive SSEs. |
I wonder if Djoser is buffering the response? |
Getting close. So I took the Chat example that was apparently working (when the static files are served from Django) and pointed my Frontend to use its API. |
Hmm, so the chat example works when connected to via the client code served by the app, but not when connecting to it from client code not served by the app? Maybe a CORS issue? |
Well I've modified every CORS setting I can find, no luck - and again normal REST API calls for the same server have no issue. I also tried the settings in the readme for allow origin and withcredentials, no effect. Is there a way to set custom headers in the SSE response? I'm noting the response header from
I've seen with other projects where both gzip and chunked transfer encoding can cause issues. With those we could user custom headers to enable/disable them in the response - is there a way to do it with this library? EDIT: Actually I may have indirectly figured this out, but the above question does stand because its definitely the more ideal solution. I eventually served the frontend out an nginx container with the following parameters for its "proxy pass" (i.e. handling traffic with the backend server):
And it worked. However, I can't get it to work in any other setup. These parameters have corresponding headers that can be sent in an SSE response so the above question about setting them stands. For reference, a working response header consisted only of:
While a not working one had the additions of
end EDITAlso, when running with anything besides runserver I'm also getting a lot of |
If Nginx is in front, you definitely need to disable buffering. I'm not seeing gzip when testing directly against Daphne. Maybe that's coming from Nginx also? |
Yes I see the need for disabling the compression/buffering and I can remove it with Nginx configs like above and then for webpack by disabling compression in their config.js. All of the setups are now working, so this issue is now solved! A final note, most of the above configurations can be set in request/response headers and will be honored by the servers. I guess my question, or maybe now more of a suggestion is, how can I set the response headers for |
Ah, I just remembered django-eventstream does set |
Thats very possible. Thats partly why I recommend having an easy way for people using this to set the response headers. It seems for each server there's something that makes in unhappy with SSE's. This time nginx required the 3 lines above while webpack only required turning off Gzip. So if people can just set their own response headers fpr Thanks for you help with this! |
I searched through the issues but couldn't find anything quite like this - though #49 may be related.
I have setup django-eventstream per the readme (with channels setup) and the client is able to connect to event channels. It is a very similar setup to the chat example.
However, calling
send_event
seemingly does nothing, no events are sent - at least it seems that way- until the server exits. Whenever the server exits (or restarts in the case of the hot loading django dev server) all of the events that should have been sent will be sent at once and received by the client. I cannot find another way to make the server finally send all these events that it is (presumably) keeping cached aside from restarting it. It seems as if there is some sort of sending buffer that needs to be flushed?This has been tried with Daphne, Daphne with HTTP 2.0 support, and Django's
runserver
interestingly all produce the same results.To be thorough - though it seems as though events are never sent by the server - I've also swapped between a webpack dev server on the frontend and an nginx server - both producing the same result.
Versions:
Django-Eventstream: 3.1.0
Django: 3.0.3
Daphne: 2.5.0
Python: 3.7.5
Is there some sort of hidden buffer setting? I searched through the code for this repo and the related GRIP repos but didn't see any smoking gun...
The text was updated successfully, but these errors were encountered: