Protect upstreamConn.history with a lock

This commit is contained in:
Simon Ser 2020-03-16 15:08:11 +01:00
parent af76c3868a
commit 1241bf82aa
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 8 additions and 1 deletions

View File

@ -555,7 +555,9 @@ func (dc *downstreamConn) register() error {
var seqPtr *uint64
if firstDownstream {
uc.lock.Lock()
seq, ok := uc.history[historyName]
uc.lock.Unlock()
if ok {
seqPtr = &seq
}
@ -583,7 +585,9 @@ func (dc *downstreamConn) register() error {
dc.user.lock.Unlock()
if lastDownstream {
uc.lock.Lock()
uc.history[historyName] = seq
uc.lock.Unlock()
}
}()
})

View File

@ -8,6 +8,7 @@ import (
"net"
"strconv"
"strings"
"sync"
"time"
"github.com/emersion/go-sasl"
@ -48,11 +49,13 @@ type upstreamConn struct {
closed bool
modes modeSet
channels map[string]*upstreamChannel
history map[string]uint64
caps map[string]string
saslClient sasl.Client
saslStarted bool
lock sync.Mutex
history map[string]uint64 // TODO: move to network
}
func connectToUpstream(network *network) (*upstreamConn, error) {