title: Streaming large files causing server to hang
body: <p>I have a feature in my web app that allows users to upload and download files. I serve up the app with Express, but the files are stored in a different server, so I proxy the requests to that server. Here's the proxy code using the <a href="https://github.com/mikeal/request" rel="nofollow">request</a> library:</p>
  
  <pre><code>module.exports = function(req, res) {
      req.headers['x-private-id'] = getId();
  
      var url = rewriteUrl(req.url);
  
      var newRequest = request(url, function(error) {
          if (error) console.log(error);
      });
  
      req.pipe(newRequest).on('response', function(res) {
          delete res.headers['x-private-id'];
      }).pipe(res);
  };
  </code></pre>
  
  <p>This works fine for all of my requests, including downloading the file. However, I run into issues when 'streaming' the file. And by streaming, I mean I use <a href="http://fancyapps.com/fancybox/" rel="nofollow">fancybox</a> to display the video using a <code>video</code> tag. The video displays fine the first few times.</p>
  
  <p>But if I close fancybox and then reopen it enough times (5 specifically), it quits working after that; the video no longer shows up. The entire Express server seems to hang, unable to process any more requests. If I restart the server, everything is OK. To me it seems like the sockets from the proxy requests aren't being closed properly, but I can't figure out why. Is there something wrong with my proxy code?</p>