-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Server-sent events not working #921
Comments
@davej would love to have a test case for this. Can you reproduce in a node only test so we could add that to our test suite? Thanks! |
Hey friends, SSE seems to be working for me, but I created a test and example for SSE here: #922 |
@aaronmaturen: Thanks for that. I was able to figure out what the issue is. node-http-proxy is timing out the response after 2 minutes of inactivity. If you change the connection handler on line 57 of the sse example to the code below then you should be able to recreate it: sse.on('connection', function(client) {
client.res.setTimeout(0); // Disable timeout
var count = 0;
setTimeout(function(){
client.send('message #' + count++);
}, 1500);
setTimeout(function(){
client.send('message #' + count++);
}, 150000);
}); On the proxy (8003), it times out after about 2 minutes (Chrome 46), with On the raw SSE server (9003), it doesn't time out and the second message is received. Is there a way to get the proxy to respect the timeout characteristics of the SSE server |
It looks like the ws proxy prevents the connection from timing out by setting the timeout option to 0; you may be able to the same with this one. I tried setting the timeout to 1000ms and it threw the error when I expected. When I set the timeout to 0 and the interval to 150000, chrome didn't throw the error again but the tab stopped showing the loading ticker after ~2minutes
|
Yes, it's easy enough to fix when you know what's wrong, thanks for your help. I guess I can close this issue unless it's worth considering setting the timeout to |
There is a SSE has a specified Content-Type of |
Any outlook for a fix or is a workaround available? |
Curious if anyone has gotten SSE events to work through the proxy? I have a UI, hitting this proxy, over to a nodejs server wanting to do SSE. In production/no proxy/using just nginx everything works great. But in my dev environment, trying to use this proxy, it never seems to let the events "get to the browser" (server 100% pushes them out etc). and on the UI side, the sse connection resets every 2 minutes (which also doesn't happen in an environment not using this proxy |
I tried with the |
I've been using this proxy with SSE for about the last year, there's an example at If I change the proxy to have a timeout of 1000ms I see the initial Could either of you provide a modified version of the sse example that doesn't send back responses so we can try to figure out what's going wrong? |
I finally found what was the issue. It comes from the https://webpack.js.org/configuration/dev-server/#devserver-compress option that was enabled. I used the It is now working, thx! 👍 |
I' ve been fighting with this one for the last couple of days. Setting |
I can't solve it. I'm nginx agent webpack vue2 |
I guess this describes the culprit with the compression: https://github.com/expressjs/compression#server-sent-events Is there a way to eagerly flush the response after each chunk recieved? |
I use create-react-app to develop a project. Since it has a pre-configured webpack-dev-server, I create a node server to run SSE on both production and development mode. In dev mode, the node server run as proxy server for the wepack-dev-server to handle SSE. So my problem is that, sse works fine in production mode. However, in dev mode, sse fail to work. The node server do send the sse message, but the front page can not receive the response. Chrome console will show up such error because of timeout: net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK) But once I modify the compress option in webpackDevServer.config file to false, everything works fine. Thanks for the tip from @thomas-hilaire, it works. |
In case you're using React and Create React App (CRA) and don't want to eject to maintain your separate webpack config just to add the compress: false option, you can pass the 'no transform' option in the Cache-Control header of your backend route for the Server Sent Event. Found out about this from another issue in CRA "If you can send a Cache-Control header with no-transform, you can avoid compression." |
I have just spend few hours figuring why my SSE not working in React App. The reason was that I was running development environment that uses
Running the exactly same code with nginx proxy works perfectly. Is there a way to debug it? Here are ouputs of
...and to the proxy:
|
Posting my solution here, since this is the first result I got from Google when dealing getting the same error. I was getting proxy
.createServer({
xfwd: true,
ws: true,
target: {
host: 'domain.com,
port: 3001,
},
agent: http.globalAgent,
ssl: {
key: fs.readFileSync(key, 'utf8'),
cert: fs.readFileSync(cert, 'utf8'),
},
}) |
My server-sent events are working except my expressjs back-end is not receiving the Has anyone gotten this combination to work? |
The problem lies in the proxy server not listening to close events emitted from the client. After closing the connection by the client i.e., Any workaround is much appreciated. |
I found a workaround. This is what I was trying to do for a few days and it is not working at all:
It will never work due to the first parameter is just the Client Request, not the actual streaming request.
Thanks to @sapphi-red & @chimurai. |
It works for a period of time and then I get an error in the browser console: "net::ERR_INCOMPLETE_CHUNKED_ENCODING"… after this it stops working.
Works perfectly if I load the site directly (i.e. not through the proxy).
Code I'm using to proxy request/responses is simply:
Previous issue was: #357
The text was updated successfully, but these errors were encountered: