diff --git a/test/parallel/test-http-many-ended-pipelines.js b/test/parallel/test-http-many-ended-pipelines.js index 4e0bc7e8ff736f..604dab7cc2c1d2 100644 --- a/test/parallel/test-http-many-ended-pipelines.js +++ b/test/parallel/test-http-many-ended-pipelines.js @@ -13,15 +13,19 @@ var http = require('http'); var net = require('net'); var numRequests = 20; -var done = 0; +var first = false; var server = http.createServer(function(req, res) { - res.end('ok'); + if (!first) { + first = true; + req.socket.on('close', function() { + server.close(); + }); + } + res.end('ok'); // Oh no! The connection died! req.socket.destroy(); - if (++done == numRequests) - server.close(); }); server.listen(common.PORT);