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

Allow provider to be garbage collected

- Global singletonNoticeLogger (set via SetNoticeWriter) retained a reference
  to the provider after Stop was called, preventing garbage collection of the
  provider object until a subsequent Start call overwrote
  singletonNoticeLogger.
Rod Hynes 3 лет назад
Родитель
Сommit
d7c40f55d4
1 измененных файлов с 18 добавлено и 16 удалено
  1. 18 16
      MobileLibrary/psi/psi.go

+ 18 - 16
MobileLibrary/psi/psi.go

@@ -263,6 +263,8 @@ func Stop() {
 		controllerCtx = nil
 		stopController = nil
 		controllerWaitGroup = nil
+		// Allow the provider to be garbage collected.
+		psiphon.SetNoticeWriter(os.Stderr)
 	}
 }
 
@@ -359,21 +361,21 @@ var sendFeedbackWaitGroup *sync.WaitGroup
 // cancelled if this function is called again before it completes.
 //
 // Warnings:
-// - Should not be used with Start concurrently in the same process
-// - An ongoing feedback upload started with StartSendFeedback should be
-//   stopped with StopSendFeedback before the process exists. This ensures that
-//   any underlying resources are cleaned up; failing to do so may result in
-//   data store corruption or other undefined behavior.
-// - Start and StartSendFeedback both make an attempt to migrate persistent
-//   files from legacy locations in a one-time operation. If these functions
-//   are called in parallel, then there is a chance that the migration attempts
-//   could execute at the same time and result in non-fatal errors in one, or
-//   both, of the migration operations.
-// - Calling StartSendFeedback or StopSendFeedback on the same call stack
-//   that the PsiphonProviderFeedbackHandler.SendFeedbackCompleted() callback
-//   is delivered on can cause a deadlock. I.E. the callback code must return
-//   so the wait group can complete and the lock acquired in StopSendFeedback
-//   can be released.
+//   - Should not be used with Start concurrently in the same process
+//   - An ongoing feedback upload started with StartSendFeedback should be
+//     stopped with StopSendFeedback before the process exists. This ensures that
+//     any underlying resources are cleaned up; failing to do so may result in
+//     data store corruption or other undefined behavior.
+//   - Start and StartSendFeedback both make an attempt to migrate persistent
+//     files from legacy locations in a one-time operation. If these functions
+//     are called in parallel, then there is a chance that the migration attempts
+//     could execute at the same time and result in non-fatal errors in one, or
+//     both, of the migration operations.
+//   - Calling StartSendFeedback or StopSendFeedback on the same call stack
+//     that the PsiphonProviderFeedbackHandler.SendFeedbackCompleted() callback
+//     is delivered on can cause a deadlock. I.E. the callback code must return
+//     so the wait group can complete and the lock acquired in StopSendFeedback
+//     can be released.
 func StartSendFeedback(
 	configJson,
 	diagnosticsJson,
@@ -461,7 +463,7 @@ func StopSendFeedback() {
 		sendFeedbackCtx = nil
 		stopSendFeedback = nil
 		sendFeedbackWaitGroup = nil
-		// Allow the notice receiver to be deallocated.
+		// Allow the notice handler to be garbage collected.
 		psiphon.SetNoticeWriter(os.Stderr)
 	}
 }