Skip to content

Instantly share code, notes, and snippets.

@Philmod
Created March 21, 2013 18:23
Show Gist options
  • Save Philmod/5215399 to your computer and use it in GitHub Desktop.
Save Philmod/5215399 to your computer and use it in GitHub Desktop.
This is simple way to reproduce the socket hang up. Hope it can help.
// npm install express supertest
// node socketHangUp.js
/**
* Express server.
*/
var express = require('express')
, request = require('supertest')
;
var app = express();
app.configure(function() {
app.use(express.bodyParser());
app.use(app.router);
});
app.get('/', function(req, res) {
res.send('hello world');
});
/**
* Requests.
*/
var i = 0
, max = 1000
, reqfn = function () {
request(app)
.get('/')
.end(function(error, res){
console.log('i = ', i++);
if (i<max) reqfn();
});
request(app)
.get('/')
.end(function(error, res){
console.log('i = ', i++);
if (i<max) reqfn();
});
};
reqfn();
/*
i = 1996
events.js:72
throw er; // Unhandled 'error' event
^
Error: socket hang up
at createHangUpError (http.js:1417:15)
at Socket.socketOnEnd [as onend] (http.js:1513:23)
at Socket.g (events.js:175:14)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:870:14
at process._tickCallback (node.js:415:13)
*/
@xdamman
Copy link

xdamman commented Apr 22, 2013

  • What version of express does it use?
  • What is supertest (in require('supertest');)

@xdamman
Copy link

xdamman commented Apr 22, 2013

I ran:

$> npm install express supertest
$> node sockethangup.js 

And this is what I got:

i =  508

events.js:66
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: listen EADDRINUSE
    at errnoException (net.js:768:11)
    at Server._listen2 (net.js:908:14)
    at listen (net.js:935:10)
    at Server.listen (net.js:984:5)
    at Test.serverAddress (/private/tmp/node_modules/supertest/lib/test.js:65:18)
    at new Test (/private/tmp/node_modules/supertest/lib/test.js:44:12)
    at Object.module.exports.methods.forEach.obj.(anonymous function) [as get] (/private/tmp/node_modules/supertest/index.js:29:14)
    at reqfn (/private/tmp/sockethangup.js:28:10)
    at reqfn (/private/tmp/sockethangup.js:38:22)
    at Test.assert (/private/tmp/node_modules/supertest/lib/test.js:195:3)
    at Test.end (/private/tmp/node_modules/supertest/lib/test.js:124:10)

@xdamman
Copy link

xdamman commented Apr 22, 2013

I'm on node 0.8.8 and express is v3.2.0

@xdamman
Copy link

xdamman commented Apr 22, 2013

Ok my bad, I had another node instance running elsewhere. Now I have this different error (still not a socket hangup:)

i =  1016
i =  1017

events.js:66
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: connect EMFILE
    at errnoException (net.js:768:11)
    at connect (net.js:644:19)
    at Socket.connect (net.js:709:9)
    at dns.js:71:18
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment