Skip to content

Commit

Permalink
Copy chunk bytes in TSDB store before sending to client
Browse files Browse the repository at this point in the history
During head compaction mmaped memory gets released while gRPC is
marshaling bytes from that same memory region. This leads to a fatal
segfault and crashes the receiver. The segfault happens when marshaling
chunks specifically.

This commit modifies the TSDB store server to copy chunk bytes before
sending them to the client. I tried running this for a while and saw
no significant increase in memory usage.

Signed-off-by: Filip Petkovski <[email protected]>
  • Loading branch information
fpetkovski committed Mar 10, 2023
1 parent 5262948 commit e65955b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/store/tsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,15 @@ func (s *TSDBStore) Series(r *storepb.SeriesRequest, srv storepb.Store_SeriesSer
return status.Errorf(codes.Internal, "TSDBStore: found not populated chunk returned by SeriesSet at ref: %v", chk.Ref)
}

chunkBytes := make([]byte, len(chk.Chunk.Bytes()))
copy(chunkBytes, chk.Chunk.Bytes())
c := storepb.AggrChunk{
MinTime: chk.MinTime,
MaxTime: chk.MaxTime,
Raw: &storepb.Chunk{
Type: storepb.Chunk_Encoding(chk.Chunk.Encoding() - 1), // Proto chunk encoding is one off to TSDB one.
Data: chk.Chunk.Bytes(),
Hash: hashChunk(hasher, chk.Chunk.Bytes(), enableChunkHashCalculation),
Data: chunkBytes,
Hash: hashChunk(hasher, chunkBytes, enableChunkHashCalculation),
},
}
frameBytesLeft -= c.Size()
Expand Down

0 comments on commit e65955b

Please sign in to comment.