Skip to content

Commit

Permalink
Poller: remore recursion and memory leak. The problem is well describ…
Browse files Browse the repository at this point in the history
…ed here: nodejs/node#6673
  • Loading branch information
michurin committed Apr 21, 2018
1 parent a34a91a commit 7cc251e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/poller.js
Original file line number Diff line number Diff line change
@@ -105,16 +105,17 @@ function process_update(data, config) { // This function have to be synchronous
}


const poll = module.exports.poller = async (last_update_id, config) => {
logger.debug(`Poll. last_update_id=${last_update_id}`);
try {
var data = await call_api(get_updates_message(config.polling_timeout, last_update_id), config.token, (config.polling_timeout + 60) * 1000);
last_update_id = Math.max(process_update(data, config), last_update_id);
} catch (error) {
logger.error('Error in polling loop:', error);
logger.info(`Going to sleep ${sleep_on_error}ms`);
await sleep(sleep_on_error);
logger.info('Continue polling after error.');
module.exports.poller = async (last_update_id, config) => {
while (true) { // eslint-disable-line no-constant-condition
logger.debug(`Poll. last_update_id=${last_update_id}`);
try {
var data = await call_api(get_updates_message(config.polling_timeout, last_update_id), config.token, (config.polling_timeout + 60) * 1000);
last_update_id = Math.max(process_update(data, config), last_update_id);
} catch (error) {
logger.error('Error in polling loop:', error);
logger.info(`Going to sleep ${sleep_on_error}ms`);
await sleep(sleep_on_error);
logger.info('Continue polling after error.');
}
}
poll(last_update_id, config);
};

0 comments on commit 7cc251e

Please sign in to comment.