Fix race in assigning keep alive timer

This commit is contained in:
Matt Joiner 2021-08-18 14:48:25 +10:00
parent dcb2e5b53b
commit 588a7b6149
1 changed files with 2 additions and 2 deletions

View File

@ -63,6 +63,8 @@ func (cn *peerConnMsgWriter) run(keepAliveTimeout time.Duration) {
lastWrite time.Time = time.Now()
keepAliveTimer *time.Timer
)
cn.mu.Lock()
defer cn.mu.Unlock()
keepAliveTimer = time.AfterFunc(keepAliveTimeout, func() {
cn.mu.Lock()
defer cn.mu.Unlock()
@ -71,8 +73,6 @@ func (cn *peerConnMsgWriter) run(keepAliveTimeout time.Duration) {
}
keepAliveTimer.Reset(keepAliveTimeout)
})
cn.mu.Lock()
defer cn.mu.Unlock()
defer keepAliveTimer.Stop()
frontBuf := new(bytes.Buffer)
for {