mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
lib/connections: Fix race condition in parallel dial, minor cleanups (fixes #4526)
This commit is contained in:
parent
0518a92cdb
commit
3312a29dde
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user