-
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
Can't set headers after they are sent #930
Comments
+1 I'm having the same problem. |
This situation happens when request() call throws an error. It looks like you have a race condition between your response error function and the web proxy. What is happening is the request() call is failing and the custom error handler and the proxy are fighting over the same response object. res.headersSent will not provide you protection because after both times you use them there is many asynchronous callbacks past them. The stack trace I am getting is indicating the error is originating in the proxy which mean the header flush was likely triggered by res.end() on line 31. This f’d up the proxy since it can no longer write headers itself because the headers were sent there. You have to rethink the fundamental structure of this app to account for the for asynchronous nature of node and http-proxy. |
+1 I'm having the same problem |
Is there a way to ignore this error and force the server keep on running? |
+1 |
+1 |
This PR tries to fix "Can't set headers after they are sent" errors. That are a lot of situations where this error can occurs. In my case, it is happening because I have others middlewares (in an expressjs application that tries to proxy requests). Some of those middlewares (like [passportjs](http://passportjs.org/), or [cors](https://www.npmjs.com/package/cors)) can run ```res.end()``` and when the proxy receive a response, it is already finished. So, it is necessary to test if we can write on the user response when the proxy response is ready. I think it could also fix http-party#930, http-party#1168, http-party#908
This PR tries to fix "Can't set headers after they are sent" errors. That are a lot of situations where this error can occurs. In my case, it is happening because I have others middlewares (in an expressjs application that tries to proxy requests). Some of those middlewares (like [passportjs](http://passportjs.org/), or [cors](https://www.npmjs.com/package/cors)) can run ```res.end()``` and when the proxy receive a response, it is already finished. So, it is necessary to test if we can write on the user response when the proxy response is ready. I think it could also fix #930, #1168, #908
This PR tries to fix "Can't set headers after they are sent" errors. That are a lot of situations where this error can occurs. In my case, it is happening because I have others middlewares (in an expressjs application that tries to proxy requests). Some of those middlewares (like [passportjs](http://passportjs.org/), or [cors](https://www.npmjs.com/package/cors)) can run ```res.end()``` and when the proxy receive a response, it is already finished. So, it is necessary to test if we can write on the user response when the proxy response is ready. I think it could also fix #930, #1168, #908
This PR tries to fix "Can't set headers after they are sent" errors. That are a lot of situations where this error can occurs. In my case, it is happening because I have others middlewares (in an expressjs application that tries to proxy requests). Some of those middlewares (like [passportjs](http://passportjs.org/), or [cors](https://www.npmjs.com/package/cors)) can run ```res.end()``` and when the proxy receive a response, it is already finished. So, it is necessary to test if we can write on the user response when the proxy response is ready. I think it could also fix #930, #1168, #908
I just got a very strange error. The proxy tries to send the header twice and I have no idea why.
My
proxy.js
file: https://gist.github.com/xolf/f79a1f939d7dc64c9894The text was updated successfully, but these errors were encountered: