Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tjfontaine/7394912 to your computer and use it in GitHub Desktop.
Save tjfontaine/7394912 to your computer and use it in GitHub Desktop.
From 626c8ac5634c543a3e922e60c83b0e2dfdd5b094 Mon Sep 17 00:00:00 2001
From: Timothy J Fontaine <tjfontaine@gmail.com>
Date: Mon, 11 Nov 2013 02:09:12 +0000
Subject: [PATCH] src: HandleWrap::OnClose needs HandleScope
---
src/handle_wrap.cc | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc
index a63421b..0839f24 100644
--- a/src/handle_wrap.cc
+++ b/src/handle_wrap.cc
@@ -144,6 +144,7 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
if (wrap->flags_ & kCloseCallback) {
assert(close_sym.IsEmpty() == false);
+ HandleScope scope;
MakeCallback(wrap->object_, close_sym, 0, NULL);
}
--
1.8.3.1
#!/usr/sbin/dtrace -s
pid$1::*HandleScopeC1*:entry
{
self->cone++;
}
pid$1::*HandleScopeD1*:entry
/self->cone/
{
self->cone--;
}
pid$1::*HandleScopeC2*:entry
{
self->ctwo++;
}
pid$1::*HandleScopeD2*:entry
/self->ctwo/
{
self->ctwo--;
}
pid$1::*_ZN4node12MakeCallbackEN2v86HandleINS0_6ObjectEEENS1_INS0_6StringEEEiPNS1_INS0_5ValueEEE*:entry
/self->cone < 1 || self->ctwo < 1/
{
@[jstack(200, 8000)] = count();
}
tick-10s
{
printf("one: %d, two: %d\n", self->cone, self->ctwo);
printa(@);
}
require('http').createServer(function(req, res) {
req.resume();
res.end();
}).listen(8000);
// Load modules
var Url = require('url');
var Http = require('http');
var ignore = function () { };
var request = function (method, url, options, callback) {
var uri = Url.parse(url);
var timeoutId;
uri.method = method.toUpperCase();
uri.headers = options.headers;
var req = Http.request(uri);
// Register handlers
var isFinished = false;
var finish = function (err, res) {
if (res) {
res.destroy();
}
req.abort();
if (!isFinished) {
isFinished = true;
req.removeAllListeners();
req.on('error', ignore);
clearTimeout(timeoutId);
return callback(err, res);
}
};
req.once('error', function (err) {
return finish(err);
});
req.once('response', function (res) {
return finish(null, res);
});
req.write(options.payload);
timeoutId = setTimeout(function () {
return finish(new Error('Client request timeout'));
}, 60000);
req.end();
};
var envelope = {
a: 1,
b: 'asd',
c: {
d: 123,
e: 'asd'
}
};
var pending = 0;
var send = function () {
var options = {
headers: {
'content-type': 'application/json'
},
payload: JSON.stringify(envelope)
};
++pending;
request('post', 'http://localhost:8000/', options, function (err, res) {
--pending;
});
};
setInterval(function () {
for (var i = 0; i < 400; ++i) {
send();
}
}, 1000);
var max = 0;
setInterval(gc, 500);
setInterval(function () {
var stats = process.memoryUsage();
if (stats.rss > max) {
max = stats.rss;
console.log('ZOMG NEW RSS', max);
}
}, 1000);
setInterval(function () {
var stats = process.memoryUsage();
console.log(stats.rss, stats.heapTotal, stats.heapUsed, pending);
}, 9997);
@tjfontaine
Copy link
Author

              node`_ZN4node12MakeCallbackEN2v86HandleINS0_6ObjectEEENS1_INS0_6StringEEEiPNS1_INS0_5ValueEEE
              node`_ZN4node10HandleWrap7OnCloseEP11uv_handle_s+0x83
              node`uv_run+0x164
              node`_ZN4node5StartEiPPc+0x17b
              node`main+0x1b
              node`_start+0x83
  _ZN4node12MakeCallbackEN2v86HandleINS0_6ObjectEEENS1_INS0_6StringEEEiPNS1_INS0_5ValueEEE            15150

15150 times MakeCallback was called without a HandleScope from OnClose

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