Skip to content

Commit 541bb95

Browse files
authored
Merge pull request #121 from arangodb/bug-fix/vst-message-chunk-mutex
Added mutex guarding message chunks.
2 parents 56ad539 + ff00d20 commit 541bb95

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

vst/protocol/message.go

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package protocol
2424

2525
import (
2626
"sort"
27+
"sync"
2728
"sync/atomic"
2829
)
2930

@@ -32,6 +33,7 @@ type Message struct {
3233
ID uint64
3334
Data []byte
3435

36+
chunksMutex sync.Mutex
3537
chunks []chunk
3638
numberOfChunks uint32
3739
responseChanClosed int32
@@ -62,6 +64,9 @@ func (m *Message) notifyListener() {
6264
// addChunk adds the given chunks to the list of chunks of the message.
6365
// If the given chunk is the first chunk, the expected number of chunks is recorded.
6466
func (m *Message) addChunk(c chunk) {
67+
m.chunksMutex.Lock()
68+
defer m.chunksMutex.Unlock()
69+
6570
m.chunks = append(m.chunks, c)
6671
if c.IsFirst() {
6772
m.numberOfChunks = c.NumberOfChunks()
@@ -73,6 +78,9 @@ func (m *Message) addChunk(c chunk) {
7378
// is returned.
7479
// If all chunks are available, the Data field is build and set and true is returned.
7580
func (m *Message) assemble() bool {
81+
m.chunksMutex.Lock()
82+
defer m.chunksMutex.Unlock()
83+
7684
if m.Data != nil {
7785
// Already assembled
7886
return true

0 commit comments

Comments
 (0)