title: node.js Error: read ECONNRESET
body: <p>I m running an Express 4 application, and I added some logic to router:</p>
  
  <pre><code>router.get('/pars', function(req, res, next) {
  
      fetcher.parseXml(function(err, result){ //download files from ftp server, it can takes from 10 sec to 1 minute
          if(err) {
              console.log("router " + err);
              res.render('index', { title: err });
          }else {
              console.log(result);
              res.render('index', { title: 'Download finish' });
          }
      });
  });
  </code></pre>
  
  <p>And added coressponding button to start index page, that send ajax to that '/pars' endpoint:</p>
  
  <pre><code>...
  &lt;button id="btn"&gt;Parse Data&lt;/button&gt;
  
    &lt;script&gt;
        $( document ).ready(function() {
  
            $('#btn').click(function () {
                $.get(
                        "/pars",
                        onAjaxSuccess
                );
            });
            function onAjaxSuccess(data) {
                alert(data);
            };
        });
  &lt;/script&gt;
  </code></pre>
  
  <p>So all works fine and I sucesfully reloading page and downloading files from ftp using 'jsftp' module, but after some time (it may be 30 sec or 2 minutes ) I got error which crash all my app:</p>
  
  <pre><code>events.js:85
        throw er; // Unhandled 'error' event
              ^
  Error: read ECONNRESET
      at exports._errnoException (util.js:746:11)
      at TCP.onread (net.js:559:26)
  </code></pre>
  
  <p>I found similar problem at <a href="https://stackoverflow.com/questions/17245881/node-js-econnreset">Node js ECONNRESET</a></p>
  
  <p>And added this 'catching' code to my app.js:</p>
  
  <pre><code>process.on('uncaughtException', function (err) {
      console.error(err.stack);
      console.log("Node NOT Exiting...");
  });
  </code></pre>
  
  <p>Now app doesnt crashes, but spams that error from time to timeto my log, and all logic works fine.</p>
  
  <p>I think issue can be in ftp.get:</p>
  
  <pre><code> Ftp.get(config.get("ftpDownloader:dir") + '/'+ fileName, __dirname + '/xml/' + fileName, function(hadErr) {
          if (hadErr){
              log.error('There was an error retrieving the file.' + hadErr);
              ftpDonwloadCallback(hadErr);
          }else{
              log.info("XML WAS DOWNLOADED: " + fileName);
              readFile(fileName, ftpDonwloadCallback);
          }
      });
  </code></pre>
  
  <p>Maybe somebody can help me how I can fix that problem?</p>