@@ -485,10 +485,7 @@ func doTask(task *pb.Task) *pb.TaskResult {
485
485
func reportStateDaemon (stateClient pb.NezhaService_ReportSystemStateClient , cancel context.CancelFunc ) {
486
486
var err error
487
487
for {
488
- _ , err = doWithTimeout (func () (* int , error ) {
489
- lastReportHostInfo , lastReportIPInfo , err = reportState (stateClient , lastReportHostInfo , lastReportIPInfo )
490
- return nil , err
491
- }, time .Second * 10 )
488
+ lastReportHostInfo , lastReportIPInfo , err = reportState (stateClient , lastReportHostInfo , lastReportIPInfo )
492
489
if err != nil {
493
490
printf ("reportStateDaemon exit: %v" , err )
494
491
cancel ()
@@ -504,10 +501,12 @@ func reportState(statClient pb.NezhaService_ReportSystemStateClient, host, ip ti
504
501
}
505
502
if initialized {
506
503
monitor .TrackNetworkSpeed ()
507
- if err := statClient .Send (monitor .GetState (agentConfig .SkipConnectionCount , agentConfig .SkipProcsCount ).PB ()); err != nil {
504
+ if _ , err := doWithTimeout (func () (* pb.Receipt , error ) {
505
+ return nil , statClient .Send (monitor .GetState (agentConfig .SkipConnectionCount , agentConfig .SkipProcsCount ).PB ())
506
+ }, time .Second * 10 ); err != nil {
508
507
return host , ip , err
509
508
}
510
- _ , err := statClient .Recv ( )
509
+ _ , err := doWithTimeout ( statClient .Recv , time . Second * 10 )
511
510
if err != nil {
512
511
return host , ip , err
513
512
}
@@ -534,7 +533,9 @@ func reportHost() bool {
534
533
}
535
534
defer hostStatus .Store (false )
536
535
if client != nil && initialized {
537
- receipt , err := client .ReportSystemInfo2 (context .Background (), monitor .GetHost ().PB ())
536
+ receipt , err := doWithTimeout (func () (* pb.Uint64Receipt , error ) {
537
+ return client .ReportSystemInfo2 (context .Background (), monitor .GetHost ().PB ())
538
+ }, time .Second * 10 )
538
539
if err != nil {
539
540
printf ("ReportSystemInfo2 error: %v" , err )
540
541
return false
@@ -563,7 +564,9 @@ func reportGeoIP(use6, forceUpdate bool) bool {
563
564
return true
564
565
}
565
566
566
- geoip , err := client .ReportGeoIP (context .Background (), pbg )
567
+ geoip , err := doWithTimeout (func () (* pb.GeoIP , error ) {
568
+ return client .ReportGeoIP (context .Background (), pbg )
569
+ }, time .Second * 10 )
567
570
if err != nil {
568
571
return false
569
572
}
0 commit comments