peer: Remove potential race when calling Connect.
This commit is contained in:
parent
7de7bddba9
commit
5cbd1f85bf
1 changed files with 1 additions and 2 deletions
|
@ -1953,7 +1953,7 @@ func (p *Peer) QueueInventory(invVect *wire.InvVect) {
|
||||||
// the peer is already connected will have no effect.
|
// the peer is already connected will have no effect.
|
||||||
func (p *Peer) Connect(conn net.Conn) error {
|
func (p *Peer) Connect(conn net.Conn) error {
|
||||||
// Already connected?
|
// Already connected?
|
||||||
if atomic.LoadInt32(&p.connected) != 0 {
|
if !atomic.CompareAndSwapInt32(&p.connected, 0, 1) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1963,7 +1963,6 @@ func (p *Peer) Connect(conn net.Conn) error {
|
||||||
p.conn = conn
|
p.conn = conn
|
||||||
p.timeConnected = time.Now()
|
p.timeConnected = time.Now()
|
||||||
|
|
||||||
atomic.AddInt32(&p.connected, 1)
|
|
||||||
return p.start()
|
return p.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue