chore: build with Go 1.26; use Go 1.25 features (#10570)
WaitGroup.Go and built-in gomaxprocs handling. Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
@@ -337,23 +337,20 @@ func BenchmarkConnections(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
errC := make(chan error, 2)
|
||||
go func() {
|
||||
wg.Go(func() {
|
||||
if _, err := client.Write(data); err != nil {
|
||||
errC <- err
|
||||
return
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
go func() {
|
||||
})
|
||||
wg.Go(func() {
|
||||
if _, err := io.ReadFull(server, data); err != nil {
|
||||
errC <- err
|
||||
return
|
||||
}
|
||||
total += sz
|
||||
wg.Done()
|
||||
}()
|
||||
})
|
||||
wg.Wait()
|
||||
close(errC)
|
||||
err := <-errC
|
||||
|
||||
@@ -605,15 +605,13 @@ func (s *service) dialDevices(ctx context.Context, now time.Time, cfg config.Con
|
||||
dialWG.Wait()
|
||||
dialCancel()
|
||||
}()
|
||||
for i := range queue {
|
||||
for _, entry := range queue {
|
||||
select {
|
||||
case <-dialCtx.Done():
|
||||
return
|
||||
default:
|
||||
}
|
||||
dialWG.Add(1)
|
||||
go func(entry dialQueueEntry) {
|
||||
defer dialWG.Done()
|
||||
dialWG.Go(func() {
|
||||
conn, ok := s.dialParallel(dialCtx, entry.id, entry.targets, dialSemaphore)
|
||||
if !ok {
|
||||
return
|
||||
@@ -630,7 +628,7 @@ func (s *service) dialDevices(ctx context.Context, now time.Time, cfg config.Con
|
||||
}
|
||||
}
|
||||
numConnsMut.Unlock()
|
||||
}(queue[i])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1118,12 +1116,8 @@ func (s *service) dialParallel(ctx context.Context, deviceID protocol.DeviceID,
|
||||
wg := sync.WaitGroup{}
|
||||
for _, tgt := range tgts {
|
||||
sema.Take(1)
|
||||
wg.Add(1)
|
||||
go func(tgt dialTarget) {
|
||||
defer func() {
|
||||
wg.Done()
|
||||
sema.Give(1)
|
||||
}()
|
||||
wg.Go(func() {
|
||||
defer sema.Give(1)
|
||||
conn, err := tgt.Dial(ctx)
|
||||
if err == nil {
|
||||
// Closes the connection on error
|
||||
@@ -1136,7 +1130,7 @@ func (s *service) dialParallel(ctx context.Context, deviceID protocol.DeviceID,
|
||||
l.Debugln("dialing", deviceID, tgt.uri, "success:", conn)
|
||||
res <- conn
|
||||
}
|
||||
}(tgt)
|
||||
})
|
||||
}
|
||||
|
||||
// Spawn a routine which will unblock main routine in case we fail
|
||||
|
||||
Reference in New Issue
Block a user