Skip to content

Commit 015f6c2

Browse files
committed
MB-36554: Make sure the engine won't reallocate tracing vector
The memory accounting could get out of sync if the underlying engine tried to add a trace element and the tracer needed to reallocate memory in the vector. To work around this problem make sure that there there is at least 10 free elements in the trace array before calling into the engine. Change-Id: I69144e14708bf4bcc5ee4d0c19e516cadecfebdf Reviewed-on: http://review.couchbase.org/116928 Well-Formed: Build Bot <[email protected]> Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 5b0a350 commit 015f6c2

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

daemon/mcbp_executors.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ void mcbp_execute_packet(Cookie& cookie) {
879879
if (header.isResponse()) {
880880
execute_response_packet(cookie, header.getResponse());
881881
} else {
882+
cookie.getTracer().ensureSpace();
882883
// We've already verified that the packet is a legal packet
883884
// so it must be a request
884885
execute_request_packet(cookie, header.getRequest());

tracing/tracer.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ void Tracer::clear() {
9292
vecSpans.clear();
9393
}
9494

95+
void Tracer::ensureSpace() {
96+
const size_t minimumSpaceAvailable = 10;
97+
vecSpans.reserve(vecSpans.size() + minimumSpaceAvailable);
98+
}
99+
95100
} // end namespace tracing
96101
} // end namespace cb
97102

tracing/tracer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ class MEMCACHED_PUBLIC_CLASS Tracer {
110110
friend std::string(::to_string)(const cb::tracing::Tracer& tracer,
111111
bool raw);
112112

113+
/// Ensure that there is space in the tracer so that we won't have to do
114+
/// additional memory allcation when inserting a span
115+
void ensureSpace();
116+
113117
protected:
114118
std::vector<Span> vecSpans;
115119
};

0 commit comments

Comments
 (0)