Reputation: 592
I have written a routine for queueing a set of http requests so that they happen in sequence instead of concurrently. I am using this async library: https://caolan.github.io/async/v3/. This is running in a browser in a Meteor/React stack.
Normally this code executes correctly, but maybe 1-2% of the time the first task in the queue returns, and the queue fails to call its callback and fails to process subsequent tasks in the queue. The error callback never fires, and the queue never empties.
Are there known errors with this library? Is there some error in my code? Are there any approaches for troubleshooting what is happening to freeze the queue?
import async from 'async';
const taskWorker = async requestPayload => {
console.debug( 'taskWorker started' );
const result = await makeAnHttpRequest( requestPayload );
console.debug( 'taskWorker complete' );
return result;
};
console.debug( 'creating async queue.' );
const taskQueue = async.queue( taskWorker, 1 );
taskQueue.drain( () => {
console.debug( 'all items have been processed' );
} );
taskQueue.error( ( err, task ) => {
console.error( 'task experienced an error' );
} );
export const requestItem = requestPayload => {
console.debug( 'requestItem started' );
return new Promise( ( resolve, reject ) => {
console.debug( 'requestItem promise started' );
taskQueue.push(
requestPayload,
( error, result ) => {
console.debug( 'taskQueue callback' );
if ( error ) {
reject( error );
}
else {
resolve( result );
}
} );
} );
};
Typical output:
creating async queue.
requestItem started
requestItem started
requestItem started
requestItem promise started
requestItem promise started
requestItem promise started
taskWorker started
taskWorker complete
taskQueue callback
taskWorker started
taskWorker complete
taskQueue callback
taskWorker started
taskWorker complete
taskQueue callback
all items have been processed
But in some conditions I see this output instead, and it stays like this indefinitely.
creating async queue.
requestItem started
requestItem started
requestItem started
requestItem promise started
requestItem promise started
requestItem promise started
taskWorker started
taskWorker complete
I would expect that the queue would either proceed to the callback for the first task, or it would print 'task experienced an error'
, but it does neither!
Upvotes: 0
Views: 44