Skip to content

Commit c1f3b21

Browse files
timjrobinsonlpinca
authored andcommitted
[fix] Fix stack overflow crash
1 parent 1653db1 commit c1f3b21

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/Sender.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,10 @@ Sender.prototype.flush = function() {
267267
var self = this;
268268

269269
handler(function() {
270-
self.processing = false;
271-
self.flush();
270+
process.nextTick(function() {
271+
self.processing = false;
272+
self.flush();
273+
});
272274
});
273275
};
274276

test/Sender.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ describe('Sender', function() {
6060
});
6161
sender.send('hi', { compress: true });
6262
});
63+
64+
it('handles many send calls while processing without crashing on flush', function(done) {
65+
var count = 0;
66+
var sender = new Sender({
67+
write: function() {
68+
if (++count > 10000) return done();
69+
}
70+
});
71+
72+
for (var i = 0; i < 10000; i++) {
73+
sender.processing = true;
74+
sender.send('hi', { compress: false, fin: true });
75+
}
76+
77+
sender.processing = false;
78+
sender.send('hi', { compress: false, fin: true });
79+
});
6380
});
6481

6582
describe('#close', function() {

0 commit comments

Comments
 (0)