-
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' with express #953
Comments
Having the same issue under load. My set up is almost identical |
I ran into this too; it only seems to happen for multipart (chunked) responses. I didn't dig into it too much, but I found a workaround. When you call the proxy method, you pass in an options object -- the third parameter, which contains the target. Well apparently, if this object contains a 'headers' object, those headers are copied to the proxied request as it's being initialized, and the timing of this copy avoids whatever race condition is causing this failure. From my code:
|
+1, happens during bigger load |
+1 |
not sure your exact use case but I ended up writing something that handled this better. Have used it in production for over a year handling multi millions of requests, and am now open sourcing it: |
+1 |
object.keys in web-incoming.js results in a non-deterministic ordering of keys, which means that in web-outgoing writeHead might be called before setHeader, which throws an error
object.keys in web-incoming.js results in a non-deterministic ordering of keys, which means that in web-outgoing writeHead might be called before setHeader, which throws an error
object.keys in web-incoming.js results in a non-deterministic ordering of keys, which means that in web-outgoing writeHead might be called before setHeader, which throws an error
object.keys in web-incoming.js results in a non-deterministic ordering of keys, which means that in web-outgoing writeHead might be called before setHeader, which throws an error
my node.js version is 4.2.2
app.js:
var api = require('./routes/api'); app.use('/api', api);
api.js
proxy.on('proxyReq', function(proxyReq, req, res, options) { proxyReq.setHeader('X-Special-Proxy-Header', 'foobar'); }); router.all("/*", function(req, res){ proxy.web(req, res, { target: 'http://dev.lalocal.cn:8080/api' }); });
error:
Error: Can't set headers after they are sent.
The text was updated successfully, but these errors were encountered: