Node.js Stream API leak

Viewed 6444

while playing with node streams I noticed that pretty much every tutorial teaches something like:

// Get Google's home page.
require('http').get("http://www.google.com/", function(response) {
  // The callback provides the response readable stream.
  // Then, we open our output text stream.
  var outStream = require('fs').createWriteStream("out.txt");

  // Pipe the input to the output, which writes the file.
  response.pipe(outStream);
});

But this is a pretty dangerous piece of code, in my opinion. What happens if the file stream throws an exception at some point? I think the file stream could leak memory because according to the docs the file stream is obviously not closed.

Do I should care? In my opinion node.js streams should handle situations...

2 Answers
Related