Skip to content

Instantly share code, notes, and snippets.

@othiym23
Forked from dizzyd/Errors
Created December 8, 2012 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save othiym23/0d418c1d78a4e28445fe to your computer and use it in GitHub Desktop.
Save othiym23/0d418c1d78a4e28445fe to your computer and use it in GitHub Desktop.
bottom is output of the top run using NODE_DEBUG=net,event node sample.js
'use strict';
var k = 1;
var events = require('events');
var emit = events.EventEmitter.prototype.emit;
events.EventEmitter.prototype.emit = function () {
var type = arguments[0];
if (type !== 'close') return emit.apply(this, arguments);
if (!this._events) return false;
var closeListeners = this._events[type];
if (closeListeners &&
Array.isArray(closeListeners) &&
closeListeners.length > 10) {
var sliced = Array.prototype.slice.call(closeListeners);
console.log("%d: class - %s", k, this.constructor.name);
console.log("%d: type - %s", k, type);
console.log("%d: closeListeners length - %s", k, sliced.length);
console.log("%d: max closeListeners value - %s", k, sliced[sliced.length - 1]);
console.dir(this);
// debugger;
}
return emit.apply(this, arguments);
};
var request = require('request');
function hambulance() {
var req = request.head({
url : 'http://short.co/97k9',
headers : {
'User-Agent': 'AppleWebKit/525.13 (KHTML, like Gecko) Safari/525.13.',
'Connection': 'close'
},
followRedirect : false
}, function (err, res, body) {
var json = JSON.stringify(res);
if (err) console.log("%d: Err: %j", k, err);
k += 1;
process.nextTick(hambulance);
});
}
hambulance();
NET: connect: find host short.co
NET: afterConnect
NET: Drain the connect queue
NET: destroy
NET: close
NET: connect: find host short.co
NET: afterConnect
NET: Drain the connect queue
NET: destroy
NET: close
NET: connect: find host short.co
NET: afterConnect
NET: Drain the connect queue
NET: destroy
NET: close
4: class - Socket
4: type - close
4: closeListeners length - 10383
4: max closeListeners value - undefined
{ domain: null,
_events:
{ free: [Function],
close:
[ [Function],
[Function: socketCloseListener],
,
,
... 10,000+ lines deleted...
,
,
[10382]: undefined ],
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: false,
sendDate: false,
_hasBody: true,
_trailer: '',
finished: true,
agent:
{ domain: null,
_events: [Object],
_maxListeners: 10,
options: {},
requests: {},
sockets: [Object],
maxSockets: 5,
createConnection: [Function] },
socketPath: undefined,
method: 'HEAD',
path: '/97k9',
_headers:
{ 'user-agent': 'AppleWebKit/525.13 (KHTML, like Gecko) Safari/525.13.',
connection: 'close',
host: 'short.co',
cookie: 'fc=fcVal=6232838655089761726',
'content-length': 0 },
_headerNames:
{ 'user-agent': 'User-Agent',
connection: 'Connection',
host: 'host',
cookie: 'cookie',
'content-length': 'content-length' },
_header: 'HEAD /97k9 HTTP/1.1\r\nUser-Agent: AppleWebKit/525.13 (KHTML, like Gecko) Safari/525.13.\r\nConnection: close\r\nhost: short.co\r\ncookie: fc=fcVal=6232838655089761726\r\ncontent-length: 0\r\n\r\n',
_headerSent: true,
socket: [Circular],
connection: [Circular],
parser: null,
res:
{ domain: null,
_events: [Object],
_maxListeners: 10,
socket: [Circular],
connection: [Circular],
httpVersion: '1.1',
complete: true,
headers: [Object],
trailers: {},
readable: false,
_paused: false,
_pendings: [Object],
_endEmitted: true,
url: '',
method: null,
statusCode: 200,
client: [Circular],
httpVersionMajor: 1,
httpVersionMinor: 1,
upgrade: false,
request: [Object],
toJSON: [Function: toJSON],
req: [Circular] } },
ondata: null,
onend: null,
_connectQueue: null,
readable: false,
_idleNext: null,
_idlePrev: null,
_idleTimeout: -1 }
events.js:126
listeners[i].apply(this, args);
^
TypeError: Cannot call method 'apply' of undefined
at Socket.EventEmitter.emit (events.js:126:20)
at Socket.events.EventEmitter.emit (/Users/forrest/Documents/projects/newrelic/nodejs-agent-git/sample.js:26:15)
at Socket._destroy.destroyed (net.js:357:10)
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