Last active
August 29, 2015 13:56
-
-
Save victorquinn/9004347 to your computer and use it in GitHub Desktop.
Bluebird memory leak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise = require('bluebird'), | |
express = require('express'), | |
request = require('request'), | |
step = require('step'); | |
var app = express(); | |
// test endpoint to test this request | |
app.post('/test', function(req, res) { | |
res.json({success: true}); | |
}); | |
var server = app.listen(3000); | |
function make_request_normal(callback) { | |
request.post({ | |
url: "http://localhost:3000/test", | |
method: "POST", | |
body: JSON.stringify({first_name: "Victor"}) | |
}, function(err, response, body) { | |
callback(err, response, body); | |
}); | |
} | |
function make_request_with_step(callback) { | |
step( | |
function() { | |
// noop | |
this(null, 'test'); | |
}, | |
function(err, test) { | |
request.post({ | |
url: "http://localhost:3000/test", | |
method: "POST", | |
body: JSON.stringify({first_name: "Victor"}) | |
}, this); | |
}, | |
function(err, response, body) { | |
callback(null, response, body); | |
} | |
); | |
} | |
// Works fine | |
// make_request(function(err, response) { | |
// console.log(body); | |
// server.close(); | |
// }); | |
// Blows up? | |
// Promise.promisify(make_request_normal)().spread(function(response, body) { | |
// console.log(response); | |
// console.log(body); | |
// server.close(); | |
// }); | |
Promise.promisify(make_request_with_step)().spread(function(response, body) { | |
console.log(body); | |
server.close(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"bluebird": "~0.11.5-0", | |
"request": "~2.33.0", | |
"express": "~3.4.8", | |
"step": "0.0.5" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment