Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions internal/cli/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"slices"
"strconv"
"strings"
"sync"
"text/template"
"time"

Expand Down Expand Up @@ -220,18 +221,32 @@ func (d *Doctor) checkNetwork(ntw mtglib.Network) bool {
dcs := slices.Collect(maps.Keys(essentials.TelegramCoreAddresses))
slices.Sort(dcs)

errs := make([]error, len(dcs))

var wg sync.WaitGroup
for i, dc := range dcs {
wg.Go(func() {
defer func() {
if r := recover(); r != nil {
errs[i] = fmt.Errorf("panic: %v", r)
}
}()
errs[i] = d.checkNetworkAddresses(ntw, essentials.TelegramCoreAddresses[dc])
})
}
wg.Wait()

ok := true

for _, dc := range dcs {
err := d.checkNetworkAddresses(ntw, essentials.TelegramCoreAddresses[dc])
if err == nil {
for i, dc := range dcs {
if errs[i] == nil {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a flaw in the logic: if checkNetworkAdresses panics (for any reason), then nothing will be written in the array.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a recover inside the goroutine that stores the panic as that DC's error, so one bad probe no longer kills the whole doctor run.

tplODCConnect.Execute(os.Stdout, map[string]any{ //nolint: errcheck
"dc": dc,
})
} else {
tplEDCConnect.Execute(os.Stdout, map[string]any{ //nolint: errcheck
"dc": dc,
"error": err,
"error": errs[i],
})
ok = false
}
Expand Down
Loading