Squash a whole load of races (and mutex half the world)

This commit is contained in:
Neil Alexander 2019-04-20 11:53:38 +01:00
parent 24281d4049
commit f3e742a297
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 66 additions and 20 deletions

View file

@ -5,6 +5,7 @@ import (
"errors"
"io/ioutil"
"net"
"sync"
"time"
"github.com/gologme/log"
@ -273,7 +274,9 @@ func (c *Core) ListenConn() (*Listener, error) {
// and the second parameter should contain a hexadecimal representation of the
// target node ID.
func (c *Core) Dial(network, address string) (Conn, error) {
conn := Conn{}
conn := Conn{
sessionMutex: &sync.RWMutex{},
}
nodeID := crypto.NodeID{}
nodeMask := crypto.NodeID{}
// Process
@ -298,6 +301,8 @@ func (c *Core) Dial(network, address string) (Conn, error) {
conn.core.router.doAdmin(func() {
conn.startSearch()
})
conn.sessionMutex.Lock()
defer conn.sessionMutex.Unlock()
return conn, nil
}