node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

Error: socket hang up

Open martindale opened this issue 11 years ago • 6 comments

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.

martindale avatar Mar 29 '15 21:03 martindale

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

lsvx avatar Apr 01 '15 00:04 lsvx

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.

lsvx avatar Apr 06 '15 18:04 lsvx

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

martindale avatar Apr 06 '15 18:04 martindale

Rock on!

lsvx avatar Apr 06 '15 18:04 lsvx

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);
});

DominicDunbar avatar Oct 26 '18 20:10 DominicDunbar

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

guguji5 avatar Jul 17 '20 02:07 guguji5