Node-http-proxy: Error: socket hang up

Created on 29 Mar 2015  路  6Comments  路  Source: http-party/node-http-proxy

I'm able to reproduce this error on an HTTPS proxy, running Ubuntu 14.04:

/someproject/node_modules/http-proxy/lib/http-proxy/index.js:119
    throw err;
          ^
Error: socket hang up
    at createHangUpError (http.js:1473:15)
    at Socket.socketCloseListener (http.js:1523:23)
    at Socket.emit (events.js:95:17)
    at TCP.close (net.js:466:12)

Reproduction Steps:

  1. Run HTTPS proxy,
  2. Enable WebSockets,
  3. Run siege https://myserver.whatever,
  4. CTRL+C and observer error on server.

Most helpful comment

Definitely due to not catching the proxy's emitted errors. Adding a basic:

proxy.on('error', function(err) {
    return console.log(err);
};

fixes the issue.

All 6 comments

I am getting the exact same error, but it is seems like it is a recent development.

Definitely due to not catching the proxy's emitted errors. Adding a basic:

proxy.on('error', function(err) {
    return console.log(err);
};

fixes the issue.

Yeah, I fixed the same thing this morning. Thanks!

Rock on!

This is how I solve the issue

var apiProxy=httpProxy.createProxyServer({
    target:{
        protocol: 'https:', // if you are running a http domain or localhost use http otherwise use https
        host: 'localhost ', // or the domain where your api is located
        port: 3000          // whatever port your api is running on
    },
    changeOrigin: true
});

webserver.get('/signup',function(req,res){
    apiProxy.web(req,res);
});

I meet this problem, it doesn't fix my error
proxy.on('error', function(err) { return console.log(err); };

Was this page helpful?
0 / 5 - 0 ratings

Related issues

catamphetamine picture catamphetamine  路  6Comments

lgzhang picture lgzhang  路  4Comments

karthikus picture karthikus  路  3Comments

tbc1 picture tbc1  路  4Comments

DominicTobias picture DominicTobias  路  3Comments