Skip to content

Commit 2f2dda9

Browse files
committed
quic: Limit blob buffer coalescence
1 parent bc84698 commit 2f2dda9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/node_blob.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ void Blob::Reader::Pull(const FunctionCallbackInfo<Value>& args) {
352352
Environment* env;
353353
std::vector<DataQueue::Vec> vecs;
354354
std::list<bob::Done> dones;
355+
size_t byte_count = 0;
355356
bool innext = false;
356357
};
357358
// TODO(@jasnell): A unique_ptr is likely better here but making this a unique
@@ -380,24 +381,26 @@ void Blob::Reader::Pull(const FunctionCallbackInfo<Value>& args) {
380381
if (count > 0) {
381382
impl->vecs.insert(impl->vecs.end(), vecs, vecs + count);
382383
impl->dones.push_back(std::move(doneCb));
384+
for (size_t n = 0; n < count; n++) impl->byte_count += vecs[n].len;
383385
}
384386
if (impl->innext) {
385387
CHECK(status != bob::STATUS_WAIT);
386388
return;
387389
}
388-
if (status == bob::STATUS_CONTINUE) {
390+
if (status == bob::STATUS_CONTINUE && impl->byte_count < 16384) {
389391
// We pull some more,
390392
// but it must be sync as we
391393
// merge it together
392394
impl->innext = true;
393-
while (status == bob::STATUS_CONTINUE) {
395+
while (status == bob::STATUS_CONTINUE && impl->byte_count < 16384) {
394396
auto snext = [impl](int status,
395397
const DataQueue::Vec* vecs,
396398
size_t count,
397399
bob::Done doneCb) {
398400
if (count > 0) {
399401
impl->vecs.insert(impl->vecs.end(), vecs, vecs + count);
400402
impl->dones.push_back(std::move(doneCb));
403+
for (size_t n = 0; n < count; n++) impl->byte_count += vecs[n].len;
401404
}
402405
};
403406
status = impl->reader->inner_->Pull(

0 commit comments

Comments
 (0)