From 88c16a96d8be84287e9e17d2030a547d8800e313 Mon Sep 17 00:00:00 2001 From: Paul Mougel Date: Fri, 22 Nov 2013 17:21:32 +0100 Subject: [PATCH] Fix stack overflow in async.queue It happened when too many synchronous tasks were queued. Fix #413 --- lib/async.js | 2 +- test/test-async.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/async.js b/lib/async.js index cb6320d6a..59f8ea6ac 100755 --- a/lib/async.js +++ b/lib/async.js @@ -722,7 +722,7 @@ if (q.drain && q.tasks.length + workers === 0) { q.drain(); } - q.process(); + async.setImmediate(q.process); }; var cb = only_once(next); worker(task.data, cb); diff --git a/test/test-async.js b/test/test-async.js index ff401e75b..fb9945cdb 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -2061,6 +2061,15 @@ exports['queue bulk task'] = function (test) { }, 800); }; +exports['queue big stack'] = function (test) { + var q = async.queue(function (task, callback) { + callback(); + }, 1); + var i; + for (i = 0 ; i < 10000 ; i++) q.push(1); + q.drain = test.done; +}; + exports['cargo'] = function (test) { var call_order = [], delays = [160, 160, 80];