Skip to content

Commit 9d7c7f8

Browse files
committed
avoid stack overflow due to cached resolving
1 parent adfbc74 commit 9d7c7f8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/CachedInputFileSystem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ class CacheBackend {
171171
// Check in cache
172172
let cacheEntry = this._data.get(path);
173173
if (cacheEntry !== undefined) {
174-
if (cacheEntry.err) return callback(cacheEntry.err);
175-
return callback(null, cacheEntry.result);
174+
if (cacheEntry.err) return process.nextTick(callback, cacheEntry.err);
175+
return process.nextTick(callback, null, cacheEntry.result);
176176
}
177177

178178
// Check if there is already the same operation running

test/CachedInputFileSystem.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,18 @@ describe("CachedInputFileSystem CacheBackend", function () {
254254
});
255255
});
256256
});
257+
258+
it("should not stack overflow when resolving in an async loop", done => {
259+
let i = 10000;
260+
const next = () => {
261+
fs.stat(__dirname, (err, result) => {
262+
if (i-- > 0) {
263+
next();
264+
} else {
265+
done();
266+
}
267+
});
268+
};
269+
next();
270+
});
257271
});

0 commit comments

Comments
 (0)