0

I'm writing a small node server, hosted in nodejitsu, that fetchs changes continuously from a cloudant db that's being modified all the time.

I'm using the follow module, that provides an interesting couchdb changes fetcher. The problem I'm having is that I want the server to work without reboots. I mean, to work continuously, non-stop. But I've found that sometimes my nodejitsu server is rebooted. For example, I left it yesterday working at 3:30 pm, and it got rebooted today around 8 am. I've discovered that the 'death' of the server happens when a timeout event is triggered by the follow module. I think I should handle this event, but I don't know how. This timeout is related, I think, to the heartbeat from cloudant.

I have written something like:

feed.on('timeout', function (err){
    console.log("Timeout!");
});

And the changes are fetched this way:

var feed = new follow.Feed({db:"https://"+user+":"+password+"@"+host+"/"+dbSource,since:"now",filter:"sync/notSynchronizedFilter"});

feed.on('change',function (change){
    //...do stuff
});

EDIT: There is an interesting thing. Right after the timeout event is triggered, an error occurs:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: getaddrinfo ENOTFOUND
    at errnoException (dns.js:37:11)
    at Object.onanswer [as oncomplete] (dns.js:124:16)

EDIT 2: More info.

I 've finally changed the heartbeat to 5 minutes, to make it very difficult to get the timeout. This kind of solved my particualr problem, but doesn't answer the original question. Regarding the error, I think it might have to do with the 'follow' module (I mean a bug), but I'm not sure.

Thanks in advance!!

Bruno.

Bruno
  • 115
  • 2
  • 10
  • So your app crashes? You need to listen to `uncaughtException` event and log the error somewhere to have an understanding of what is going on – vkurchatkin Dec 13 '13 at 14:02
  • Thanks for your reply! Yes, it crashes. You mean process.on('uncaughtException'...) ? I'll try it out. I forgot to say that the code also checks if the follow error event is triggered (feed.on('error'..)), but it is not. – Bruno Dec 13 '13 at 14:14
  • Checking the console where the server was logging I found the uncaughtExecption, triggered after the timeout: events.js:72 throw er; // Unhandled 'error' event ^ Error: getaddrinfo ENOTFOUND at errnoException (dns.js:37:11) at Object.onanswer [as oncomplete] (dns.js:124:16) – Bruno Dec 13 '13 at 14:23
  • I've edited the question adding this error thing. – Bruno Dec 13 '13 at 15:49

0 Answers0