node.js - Amazon SQS with aws-sdk receiveMessage Stall -


i'm using aws-sdk node module (as far can tell) approved way poll messages.

which sums to:

        sqs.receivemessage({             queueurl: queueurl,             maxnumberofmessages: 10,             waittimeseconds: 20         }, function(err, data) {             if (err) {                 logger.fatal('error on message recieve');                 logger.fatal(err);             } else {                 //                 if (undefined === data.messages) {                     logger.info('no messages object');                 } else if (data.messages.length > 0) {                     logger.info('messages count: ' + data.messages.length);                      var delete_batch = new array();                     (var x=0;x<data.messages.length;x++) {                         // process                         receivemessage(data.messages[x]);                          // flag delete                          var pck = new array();                         pck['id'] = data.messages[x].messageid;                         pck['receipthandle'] = data.messages[x].receipthandle;                          delete_batch.push(pck);                     }                      if (delete_batch.length > 0) {                         logger.info('calling delete');                         sqs.deletemessagebatch({                             entries: delete_batch,                             queueurl: queueurl                         }, function(err, data) {                             if (err) {                                 logger.fatal('failed delete messages');                                 logger.fatal(err);                             } else {                                 logger.debug('deleted recieved ok');                             }                         });                     }                 } else {                     logger.info('no messages count');                 }             }         }); 

receivemessage "do stuff collected messages if have enough collected messages" function

occasionally, script stalling because don't response amazon @ all, example there no messages in queue consume , instead of hitting waittimeseconds , sending "no messages object", callback isn't called.

(i'm writing amazon weirdness)

what i'm asking whats best way detect , deal this, have code in place stop concurrent calls receivemessage.

the suggested answer here: nodejs sqs queue processor has code prevents concurrent message request queries (granted it's fetching 1 message time)

i have whole thing wrapped in

var running = false; runmonitorjob = setinterval(function() {     if (running) {     } else {         running = true;         // call sqs.receive     } }, 500); 

(with running = false after delete loop (not in it's callback))

my solution be

watchdogtimeout = settimeout(function() {     running = false; }, 30000); 

but surely leave pile of floating sqs.receive's lurking , memory on time?

(this job runs time, , left running on friday, stalled saturday morning , hung till manually restarted job morning)

edit: have seen cases hangs ~5 minutes , gets messages but wait time of 20 seconds should throw "no messages" after 20 seconds. watchdog of ~10 minutes might more practical (depending on rest of ones business logic)

edit: yes long polling configured queue side.

edit: under (latest) v2.3.9 of aws-sdk , nodejs v4.4.4


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -