title: Nodejs application hangs after page refresh
body: <p>What would be the cause for having a request done and after refreshing page(aka making a new request) page hang(is loading forever) ? How can I debug this thing ?</p>
  
  <p>My code looks something like:</p>
  
  <pre><code>if(params are not good){
      res.status(500).json("Invalid date.");
  }else{
      doDatabaseQuery(callback);
      callback.onSuccess(data) =&gt; res.status(200).json(data);
      callback.onError(err) =&gt; res.status(500).json(err);
  }
  </code></pre>
  
  <p>If I change code and instead of <code>res.status(200).json(data)</code> I have <code>return res.status(200)...</code> I get: <code>Can\'t set headers after they are sent.</code> after more than 1 request.</p>
  
  <p>EDIT:</p>
  
  <p>The problem seems to be that <code>doDatabaseQuery()</code>. This method just call .find({}) on a mongoose model. Does the async request isn't killed when I press the refresh button ?</p>