Skip to content

Commit 717c6d9

Browse files
authored
fix: map race in GS transport (#208)
1 parent e69af10 commit 717c6d9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

transport/graphsync/graphsync.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ func newGSKeyToChannelIDMap() *gsKeyToChannelIDMap {
10841084
}
10851085

10861086
// get the value for a key
1087-
func (m gsKeyToChannelIDMap) load(key graphsyncKey) (datatransfer.ChannelID, bool) {
1087+
func (m *gsKeyToChannelIDMap) load(key graphsyncKey) (datatransfer.ChannelID, bool) {
10881088
m.lk.RLock()
10891089
defer m.lk.RUnlock()
10901090

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

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

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

11091109
// set the value for a key
1110-
func (m gsKeyToChannelIDMap) set(key graphsyncKey, val datatransfer.ChannelID) {
1110+
func (m *gsKeyToChannelIDMap) set(key graphsyncKey, val datatransfer.ChannelID) {
11111111
m.lk.Lock()
11121112
defer m.lk.Unlock()
11131113

11141114
m.m[key] = val
11151115
}
11161116

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

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

11271127
// delete any keys that reference this value
1128-
func (m gsKeyToChannelIDMap) deleteRefs(id datatransfer.ChannelID) {
1128+
func (m *gsKeyToChannelIDMap) deleteRefs(id datatransfer.ChannelID) {
11291129
m.lk.Lock()
11301130
defer m.lk.Unlock()
11311131

0 commit comments

Comments
 (0)