Skip to content

Commit

Permalink
Fix data race in message
Browse files Browse the repository at this point in the history
  • Loading branch information
iwanbk committed Mar 24, 2019
1 parent 0610569 commit 7eebcef
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,22 @@ func newMessageFromBuf(b []byte) (*message, error) {
}

func (m *message) add(key, val string, expired int64, deleted bool) {
m.mux.Lock()
m.Entries[key] = entry{
Key: key,
Val: val,
Expired: expired,
Deleted: deleted,
}
m.mux.Unlock()
}

// Encode implements mesh.GossipData.Encode
// TODO: split the encoding by X number of keys
func (m *message) Encode() [][]byte {
m.mux.RLock()
defer m.mux.RUnlock()

b, err := marshal(m)
if err != nil {
log.Printf("failed to encode message: %v", err)
Expand Down

0 comments on commit 7eebcef

Please sign in to comment.