mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
rafthttp: fix race on peer status activeSince
This commit is contained in:
parent
b24d0032d2
commit
c5af1d7a88
@ -219,7 +219,7 @@ func (p *peer) attachOutgoingConn(conn *outgoingConn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *peer) activeSince() time.Time { return p.status.activeSince }
|
func (p *peer) activeSince() time.Time { return p.status.activeSince() }
|
||||||
|
|
||||||
// Pause pauses the peer. The peer will simply drops all incoming
|
// Pause pauses the peer. The peer will simply drops all incoming
|
||||||
// messages without returning an error.
|
// messages without returning an error.
|
||||||
|
@ -31,7 +31,7 @@ type peerStatus struct {
|
|||||||
id types.ID
|
id types.ID
|
||||||
mu sync.Mutex // protect variables below
|
mu sync.Mutex // protect variables below
|
||||||
active bool
|
active bool
|
||||||
activeSince time.Time
|
since time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPeerStatus(id types.ID) *peerStatus {
|
func newPeerStatus(id types.ID) *peerStatus {
|
||||||
@ -46,7 +46,7 @@ func (s *peerStatus) activate() {
|
|||||||
if !s.active {
|
if !s.active {
|
||||||
plog.Infof("the connection with %s became active", s.id)
|
plog.Infof("the connection with %s became active", s.id)
|
||||||
s.active = true
|
s.active = true
|
||||||
s.activeSince = time.Now()
|
s.since = time.Now()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ func (s *peerStatus) deactivate(failure failureType, reason string) {
|
|||||||
plog.Errorf(msg)
|
plog.Errorf(msg)
|
||||||
plog.Infof("the connection with %s became inactive", s.id)
|
plog.Infof("the connection with %s became inactive", s.id)
|
||||||
s.active = false
|
s.active = false
|
||||||
s.activeSince = time.Time{}
|
s.since = time.Time{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
plog.Debugf(msg)
|
plog.Debugf(msg)
|
||||||
@ -69,3 +69,9 @@ func (s *peerStatus) isActive() bool {
|
|||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
return s.active
|
return s.active
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *peerStatus) activeSince() time.Time {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
return s.since
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user