Proxy Buffers EventSources
See original GitHub issueIs this a bug report?
Yes.
Can you also reproduce the problem with npm 4.x?
Yes.
Environment
node -v
:v8.8.1
npm -v
:5.5.1
npm ls react-scripts
(if you haven’t ejected):react-scripts@1.0.16
Then, specify:
- Operating system: Arch Linux
- Browser and version (if relevant): Firefox 57.0b13
Steps to Reproduce
I’ve got an existing app that I’d like to rewrite using React. The app has a Go backend that provides an EventSource endpoint. I attempted to use the proxy functionality of the development server to route requests for the endpoint to the Go backend.
Example Backend:
func handleEvents(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Content-Type", "text/event-stream")
for i := 0; true; i++ {
_, err := fmt.Fprintf(rw, "data: %v\n\n")
if err != nil {
break
}
rw.(http.Flusher).Flush()
}
}
Example Frontend:
let es = new EventSource('/events');
es.onmessage = (msg) => {
console.log(msg);
};
Expected Behavior
It should print a list of numbers in the browser console.
Actual Behavior
Nothing happens at all until I kill the Go backend process, at which point all of the events that the backend had sent arrive suddenly all at once. The EventSource also occasionally calls its onerror
callback and then disconnects suddenly for no apparent reason.
Note also that the code works completely fine if I serve the files produced by npm run build
directly from the Go backend.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:5 (2 by maintainers)
Top Results From Across the Web
For Server-Sent Events (SSE) what Nginx proxy configuration ...
Where most problems come from is having any type of buffering between the app server and the client. By default[4], Nginx uses proxy_buffering...
Read more >EventSource and buffering - ETOOBUSY
If your application serving the EventSource web service is behind a (reverse) proxy, you might want to know how to disable buffering.
Read more >aws-cdk/aws-lambda-event-sources module
batchSize: Determines how many records are buffered before invoking your lambda function. maxBatchingWindow: The maximum amount of time to gather records before ...
Read more >Server sent events stopped work after enabling ssl on proxy
For SSE to work properly, you must make sure nothing is getting cached or buffered: not in your script (e.g. in PHP we...
Read more >Setting up nginx to work with EventSource - Shane's blog
nginx applies a certain level of buffering which will interfer with ... /server { proxy_pass http://rack_upstream; proxy_buffering off; }.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After lurking around the internet having the same problem, I think this is related to #966. I think an ok fix would be to toggle webpack dev server’s compression via an ENV variable of some kind.
A workaround might be to enable CORS on the SSE server and connect to it directly
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs.