fanout / django-eventstream

Server-Sent Events for Django
MIT License
638 stars 84 forks source link

Firefox connection was interrupted while the page was loading #52

Closed paolodina closed 4 years ago

paolodina commented 4 years ago

I configured a simple project following Setup with Channels. As stated, I tried to connect to 127.0.0.1:8000/events/ and using Chrome everything worked fine. I also added the javascript code to receive events in the browser following the relevant docs and still no problems using Chrome.

When I connect to /events/ with Firefox (68.9.0esr) I get this download window image

and trying to receive events in the browser I get this in the Firefox web console:

The connection to http://127.0.0.1:8000/events/ was interrupted while
the page was loading. reconnecting-eventsource.js:58:21

The command I use to start Daphne is:

$ daphne project.asgi:application

django-eventstream version: latest available commit (745033a7252a7c3a69070c5a8136e23d544dd082) Django version: 3.0.4

Any idea why and a possible fix/workaround?

jkarneges commented 4 years ago

Wow, I have never seen that. You're connecting to /events/ using ReconnectingEventSource, and not attempting to navigate to /events/ in the URL bar right?

Do you get the same issue if you run the chat example in this repository and open it with Firefox?

paolodina commented 4 years ago

Hi and thanks for your answer. I'm using ReconnectingEventSource as in the docs and attempted to navigate to /events/ in the URL bar, then realized the latter was wrong (even if Chrome correctly gets the stream while FF gives the download dialog).

For simplicity I tried the time example and everything is ok in Chrome and almost in Firefox. I still see this error in FF dev console

The connection to http://127.0.0.1:8000/events/ was interrupted while
the page was loading. reconnecting-eventsource.js:58:21

It happens refreshing the page. Maybe you are able to reproduce? In my own project, the issue was more evident because I put the ReconnectingEventSource related js in a base template and having links to other pages/templates extending base, clicking on these links triggered the error more frequently (in fact every time a new page is loaded).

I still wonder if this is a problem and how it can be fixed.

jkarneges commented 4 years ago

I've seen that and I believe it's not a real problem. It happens because the existing connection gets closed when you refresh.