Browse Source

Shutdown server clients concurrently

Rod Hynes 9 months ago
parent
commit
6bbdd7f0be
1 changed files with 11 additions and 1 deletions
  1. 11 1
      psiphon/server/tunnelServer.go

+ 11 - 1
psiphon/server/tunnelServer.go

@@ -1641,9 +1641,19 @@ func (sshServer *sshServer) stopClients() {
 	sshServer.clients = make(map[string]*sshClient)
 	sshServer.clientsMutex.Unlock()
 
+	// Stop clients concurrently; if any one client stop hangs, due to a bug,
+	// this ensures that we still stop and record a server_tunnel for all
+	// non-hanging clients.
+
+	waitGroup := new(sync.WaitGroup)
 	for _, client := range clients {
-		client.stop()
+		waitGroup.Add(1)
+		go func(c *sshClient) {
+			defer waitGroup.Done()
+			c.stop()
+		}(client)
 	}
+	waitGroup.Wait()
 }
 
 func (sshServer *sshServer) handleClient(