Skip to content

Inconsistent behavior with proxyError depending on createServer invocation #185

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

Closed
n1mmy opened this issue Feb 1, 2012 · 3 comments
Closed

Comments

@n1mmy
Copy link

n1mmy commented Feb 1, 2012

How the proxy behaves when a proxyError occurs seems to depend in odd ways on how the server was invoked.

When created like this (first example in README):

var httpProxy = require('http-proxy');
var server = httpProxy.createServer(24, 'localhost');
server.listen(8000);

The proxy returns 500 with a message that the connection was refused.

However, if you start the proxy like this (second example in the README):

var httpProxy = require('http-proxy');
var server = httpProxy.createServer(function (req, res, proxy) {
  proxy.proxyRequest(req, res, {
    host: '127.0.0.1', port: 24
  });
});
server.listen(8000);

The proxied connections simply hang forever (until client timeout).

Adding custom error handling code works in both cases:

server.proxy.on('proxyError', function (err, req, res) {
  res.writeHead(500, {
    'Content-Type': 'text/plain'
  });
  res.end('Something went wrong. And we are reporting a custom error message.');  
  console.log("XXX", err);
});

This is especially confusing since the README does not mention proxyError at all.

@coderarity
Copy link
Contributor

This is probably because a RoutingProxy is being created in one case, and an HttpProxy in the other. I bet this is just a matter of copying the error handler from HttpProxy to RoutingProxy!

@coderarity
Copy link
Contributor

Guess it's not that simple! It never is.

RoutingProxy should re-emit errors from HttpProxy. There shouldn't be any differences. But RoutingProxy has been hanging when there's errors for me as well.

@indexzero
Copy link
Member

Fixed by #216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants