ETOOBUSY 🚀 minimal blogging for the impatient
If your application serving the EventSource web service is behind a (reverse) proxy, you might want to know how to disable buffering.
Which happens to serve the stuff behind an nginx instance.
The bottom line was that I wasn’t seeing any pushed message. But… after about a one-minute timeout on the session, I saw all of the pushes. So… I was suffering from buffering. (By the way, definitely check out the totally unrelated Suffering from Buffering? article from some years ago).
So, it turned out that this issue can be solved in the code itself by
adding a couple of headers, which I prompty did. So we moved from just
setting the Content-Type to
text/event-streamon to the following:
my $headers = $c->res->headers; $headers->content_type('text/event-stream'); $headers->cache_control('No-Cache'); $headers->header('X-Accel-Buffering' => 'no');
X-Accel-Buffering is recognized by most reverse-proxy
technologies to disable buffering, which makes our push message be
delivered as soon as they are produced.