Fixed deadlock in index.go

This commit is contained in:
Mathias Hall-Andersen
2017-07-17 16:16:18 +02:00
parent dd4da93749
commit c5d7efc246
8 changed files with 194 additions and 152 deletions
+2 -4
View File
@@ -6,8 +6,6 @@ import (
)
/* Index=0 is reserved for unset indecies
*
* TODO: Rethink map[id] -> peer VS map[id] -> handshake and handshake <ref> peer
*
*/
@@ -72,12 +70,12 @@ func (table *IndexTable) NewIndex(peer *Peer) (uint32, error) {
table.mutex.RLock()
_, ok := table.table[index]
table.mutex.RUnlock()
if ok {
continue
}
table.mutex.RUnlock()
// replace index
// map index to handshake
table.mutex.Lock()
_, found := table.table[index]