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

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4527
This commit is contained in:
Jakob Borg
2017-11-19 17:38:13 +00:00
committed by Audrius Butkevicius
parent 9471b9f6af
commit 72d645865e
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