Skip to content

Commit 5395fea

Browse files
authored
Merge pull request #264 from webpack/bugfix/callback-twice
fix problem where callback is called twice
2 parents d6807b5 + c12413c commit 5395fea

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/CachedInputFileSystem.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ const dirname = path => {
2121
};
2222

2323
const runCallbacks = (callbacks, err, result) => {
24-
if (callbacks.length === 1) return callbacks[0](err, result);
24+
if (callbacks.length === 1) {
25+
callbacks[0](err, result);
26+
callbacks.length = 0;
27+
return;
28+
}
2529
let error;
2630
for (const callback of callbacks) {
2731
try {

test/CachedInputFileSystem.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ describe("CachedInputFileSystem CacheBackend", function () {
212212
});
213213
});
214214

215+
it("should not call callback twice when combining sync and async calls", function (done) {
216+
let called = false;
217+
fs.stat("a", function (err, result) {
218+
if (called) return done(new Error("callback was called twice"));
219+
called = true;
220+
should.exist(result);
221+
result.a = true;
222+
done();
223+
});
224+
const syncResult = fs.statSync("a");
225+
should.exist(syncResult);
226+
should.exist(syncResult.a);
227+
});
228+
215229
it("should not join accesses with options", function (done) {
216230
fs.stat("a", function (err, result) {
217231
result.a = true;

0 commit comments

Comments
 (0)