Просмотр исходного кода

doctor: use WaitGroup.Go and recover panics in DC probes

Address review feedback on #485:
- switch to sync.WaitGroup.Go (Go 1.25+) for the per-DC goroutine
- recover panics inside the goroutine and record them as that DC's
  error, so a single panicking probe no longer crashes the whole
  doctor run and the remaining DCs still report their results
pull/485/head
Alexey Dolotov 2 дней назад
Родитель
Сommit
d6c99c7209
1 измененных файлов: 7 добавлений и 4 удалений
  1. 7
    4
      internal/cli/doctor.go

+ 7
- 4
internal/cli/doctor.go Просмотреть файл

@@ -225,11 +225,14 @@ func (d *Doctor) checkNetwork(ntw mtglib.Network) bool {
225 225
 
226 226
 	var wg sync.WaitGroup
227 227
 	for i, dc := range dcs {
228
-		wg.Add(1)
229
-		go func() {
230
-			defer wg.Done()
228
+		wg.Go(func() {
229
+			defer func() {
230
+				if r := recover(); r != nil {
231
+					errs[i] = fmt.Errorf("panic: %v", r)
232
+				}
233
+			}()
231 234
 			errs[i] = d.checkNetworkAddresses(ntw, essentials.TelegramCoreAddresses[dc])
232
-		}()
235
+		})
233 236
 	}
234 237
 	wg.Wait()
235 238
 

Загрузка…
Отмена
Сохранить