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

Fix server shutdown profile dump timing and filenames

Rod Hynes 9 месяцев назад
Родитель
Сommit
1a55f715f6
1 измененных файлов с 14 добавлено и 7 удалено
  1. 14 7
      psiphon/server/services.go

+ 14 - 7
psiphon/server/services.go

@@ -374,19 +374,26 @@ loop:
 	// During any delayed or hung shutdown, periodically dump profiles to help
 	// diagnose the cause. Shutdown doesn't wait for any running
 	// outputProcessProfiles to complete.
+	//
+	// Wait 10 seconds before the first profile dump, and at least 10
+	// seconds between profile dumps (longer when
+	// ProcessCPUProfileDurationSeconds is set).
 	signalProfileDumperStop := make(chan struct{})
+	shutdownStartTime := time.Now()
 	go func() {
-		tickSeconds := 10
-		ticker := time.NewTicker(time.Duration(tickSeconds) * time.Second)
-		defer ticker.Stop()
-		for i := tickSeconds; i <= 60; i += tickSeconds {
+		for i := 0; i < 3; i++ {
+			timer := time.NewTimer(10 * time.Second)
 			select {
 			case <-signalProfileDumperStop:
+				timer.Stop()
 				return
-			case <-ticker.C:
-				filenameSuffix := fmt.Sprintf("delayed_shutdown_%ds", i)
-				outputProcessProfiles(support.Config, filenameSuffix)
+			case <-timer.C:
 			}
+			filenameSuffix := fmt.Sprintf(
+				"delayed_shutdown_%ds",
+				time.Since(shutdownStartTime)/time.Second)
+			outputProcessProfiles(support.Config, filenameSuffix)
+
 		}
 	}()