Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Fix buffer overflow in UDPSender #395

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/reporters/udp_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,27 @@ export default class UDPSender {
return;
}

this.flush((numSpans: number, err?: string) => {
// TODO theoretically we can have buffer overflow here too, if many spans were appended during flush()
this._batch.spans.push(span);
this._totalSpanBytes += spanSize;
SenderUtils.invokeCallback(callback, numSpans, err);
this.flushWithPendingSpan(span, spanSize, callback);
}

flushWithPendingSpan(span, spanSize, callback){
this.flush((numSpans, err) => {
//Test totalSpanBytes before push
if(this._totalSpanBytes + spanSize <= this._maxSpanBytes) {
this._batch.spans.push(span);
this._totalSpanBytes += spanSize;

if (this._totalSpanBytes < this._maxSpanBytes) {
// still have space in the buffer, don't flush it yet
SenderUtils.invokeCallback(callback, numSpans, err);
return;
}
// buffer size === this._maxSpanBytes
this.flush(callback);
}else{
//Not enough space so we call recursively flushWithPendingSpan
this.flushWithPendingSpan(span, spanSize, callback);
}
});
}

Expand Down