lib/connections: Fix race condition in parallel dial, minor cleanups (fixes #4526)

This commit is contained in:
Jakob Borg 2017-11-19 18:28:02 +01:00
parent 0518a92cdb
commit 3312a29dde
3 changed files with 13 additions and 10 deletions

View File

@ -746,13 +746,13 @@ func dialParallel(deviceID protocol.DeviceID, dialTargets []dialTarget) (interna
wg := sync.NewWaitGroup()
for _, tgt := range tgts {
wg.Add(1)
go func() {
go func(tgt dialTarget) {
conn, err := tgt.Dial()
if err == nil {
res <- conn
}
wg.Done()
}()
}(tgt)
}
// Spawn a routine which will unblock main routine in case we fail

View File

@ -188,6 +188,10 @@ type dialTarget struct {
func (t dialTarget) Dial() (internalConn, error) {
l.Debugln("dialing", t.deviceID, t.uri, "prio", t.priority)
conn, err := t.dialer.Dial(t.deviceID, t.uri)
l.Debugln("dialing", t.deviceID, t.uri, "outcome", conn, err)
if err != nil {
l.Debugln("dialing", t.deviceID, t.uri, "error:", err)
} else {
l.Debugln("dialing", t.deviceID, t.uri, "success:", conn)
}
return conn, err
}

View File

@ -102,19 +102,18 @@ func (t *tcpListener) Serve() {
l.Debugln("Listen (BEP/tcp): connect from", conn.RemoteAddr())
err = dialer.SetTCPOptions(conn)
if err != nil {
if err := dialer.SetTCPOptions(conn); err != nil {
l.Debugln("Listen (BEP/tcp): setting tcp options:", err)
}
err = dialer.SetTrafficClass(conn, t.cfg.Options().TrafficClass)
if err != nil {
l.Debugln("Listen (BEP/tcp): setting traffic class:", err)
if tc := t.cfg.Options().TrafficClass; tc != 0 {
if err := dialer.SetTrafficClass(conn, tc); err != nil {
l.Debugln("Listen (BEP/tcp): setting traffic class:", err)
}
}
tc := tls.Server(conn, t.tlsCfg)
err = tlsTimedHandshake(tc)
if err != nil {
if err := tlsTimedHandshake(tc); err != nil {
l.Infoln("Listen (BEP/tcp): TLS handshake:", err)
tc.Close()
continue