Procházet zdrojové kódy

Merge pull request #49 from rod-hynes/master

Fix: allow Tunnel.Close() to be called multiple times without "panic: close of closed channel"
Adam Pritchard před 11 roky
rodič
revize
ee9c0bf745
1 změnil soubory, kde provedl 2 přidání a 1 odebrání
  1. 2 1
      psiphon/tunnel.go

+ 2 - 1
psiphon/tunnel.go

@@ -222,8 +222,8 @@ func EstablishTunnel(
 
 	// Run a goroutine to periodically execute SSH keepalive
 	sshKeepAliveQuit := make(chan struct{})
-	sshKeepAliveTicker := time.NewTicker(TUNNEL_SSH_KEEP_ALIVE_PERIOD)
 	go func() {
+		sshKeepAliveTicker := time.NewTicker(TUNNEL_SSH_KEEP_ALIVE_PERIOD)
 		for {
 			select {
 			case <-sshKeepAliveTicker.C:
@@ -258,6 +258,7 @@ func EstablishTunnel(
 func (tunnel *Tunnel) Close() {
 	if tunnel.sshKeepAliveQuit != nil {
 		close(tunnel.sshKeepAliveQuit)
+		tunnel.sshKeepAliveQuit = nil
 	}
 	if tunnel.conn != nil {
 		tunnel.conn.Close()