Flask+gevent - SSE times out with nginx+uwsgi Flask+gevent - SSE times out with nginx+uwsgi flask flask

Flask+gevent - SSE times out with nginx+uwsgi


after long hours on nginx log files and firefox js console, it turned out that the configurations shown in the question are perfectly fine.

The issue was the page reloading, this action kills and reinitializes the connection and therefore the retry command doesn't have any effect.

After removing that instruction the SSE updates work like a charm even after long time of inactivity.

Now the question is why this worked on the simpler development environment stack :-)

EDIT

indeed, after few more days, the connection still times out. I've made some time measures and found out that the time out interval is variable between some 30 seconds and several minutes of inactivity.

My conclusion is that the stack above is fine, while it's the amazon EC2 connection which expires after some variable inactivity time, since I'm still using a micro instance.

The final fix is the following JS snippet:

    evtSrc.onerror = function(e) {        location.reload();    }

the page reloads When the connection is dropped (whatever the reason). The reloads are not expected to happen when the server sent events are frequent.