Sfoglia il codice sorgente

Fix: avoid race condition potentially delaying controller shutdown

Rod Hynes 10 anni fa
parent
commit
38cf9eb18c
1 ha cambiato i file con 14 aggiunte e 0 eliminazioni
  1. 14 0
      psiphon/controller.go

+ 14 - 0
psiphon/controller.go

@@ -405,6 +405,20 @@ loop:
 		case failedTunnel := <-controller.failedTunnels:
 			NoticeAlert("tunnel failed: %s", failedTunnel.serverEntry.IpAddress)
 			controller.terminateTunnel(failedTunnel)
+
+			// Note: we make this extra check to ensure the shutdown signal takes priority
+			// and that we do not start establishing. Critically, startEstablishing() calls
+			// establishPendingConns.Reset() which clears the closed flag in
+			// establishPendingConns; this causes the pendingConns.Add() within
+			// interruptibleTCPDial to succeed instead of aborting, and the result
+			// is that it's possible for extablish goroutines to run all the way through
+			// NewSession before being discarded... delaying shutdown.
+			select {
+			case <-controller.shutdownBroadcast:
+				break loop
+			default:
+			}
+
 			// Concurrency note: only this goroutine may call startEstablishing/stopEstablishing
 			// and access isEstablishing.
 			if !controller.isEstablishing {