Skip to content

Commit

Permalink
fix: map race in GS transport (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc authored May 18, 2021
1 parent e69af10 commit 717c6d9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions transport/graphsync/graphsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ func newGSKeyToChannelIDMap() *gsKeyToChannelIDMap {
}

// get the value for a key
func (m gsKeyToChannelIDMap) load(key graphsyncKey) (datatransfer.ChannelID, bool) {
func (m *gsKeyToChannelIDMap) load(key graphsyncKey) (datatransfer.ChannelID, bool) {
m.lk.RLock()
defer m.lk.RUnlock()

Expand All @@ -1093,7 +1093,7 @@ func (m gsKeyToChannelIDMap) load(key graphsyncKey) (datatransfer.ChannelID, boo
}

// get the value if any of the keys exists in the map
func (m gsKeyToChannelIDMap) any(ks ...graphsyncKey) (datatransfer.ChannelID, bool) {
func (m *gsKeyToChannelIDMap) any(ks ...graphsyncKey) (datatransfer.ChannelID, bool) {
m.lk.RLock()
defer m.lk.RUnlock()

Expand All @@ -1107,15 +1107,15 @@ func (m gsKeyToChannelIDMap) any(ks ...graphsyncKey) (datatransfer.ChannelID, bo
}

// set the value for a key
func (m gsKeyToChannelIDMap) set(key graphsyncKey, val datatransfer.ChannelID) {
func (m *gsKeyToChannelIDMap) set(key graphsyncKey, val datatransfer.ChannelID) {
m.lk.Lock()
defer m.lk.Unlock()

m.m[key] = val
}

// call f for each key / value in the map
func (m gsKeyToChannelIDMap) forEach(f func(k graphsyncKey, chid datatransfer.ChannelID)) {
func (m *gsKeyToChannelIDMap) forEach(f func(k graphsyncKey, chid datatransfer.ChannelID)) {
m.lk.RLock()
defer m.lk.RUnlock()

Expand All @@ -1125,7 +1125,7 @@ func (m gsKeyToChannelIDMap) forEach(f func(k graphsyncKey, chid datatransfer.Ch
}

// delete any keys that reference this value
func (m gsKeyToChannelIDMap) deleteRefs(id datatransfer.ChannelID) {
func (m *gsKeyToChannelIDMap) deleteRefs(id datatransfer.ChannelID) {
m.lk.Lock()
defer m.lk.Unlock()

Expand Down

0 comments on commit 717c6d9

Please sign in to comment.