Explorar o código

Interrupt port forwards blocked on upstream reads

Rod Hynes hai 4 meses
pai
achega
bb9614e7ec
Modificáronse 2 ficheiros con 23 adicións e 0 borrados
  1. 13 0
      psiphon/common/net.go
  2. 10 0
      psiphon/server/tunnelServer.go

+ 13 - 0
psiphon/common/net.go

@@ -269,6 +269,19 @@ func (conns *LRUConns) CloseOldest() {
 	}
 	}
 }
 }
 
 
+// CloseAll closes all the connections in a
+// LRUConns.
+func (conns *LRUConns) CloseAll() {
+	conns.mutex.Lock()
+	defer conns.mutex.Unlock()
+	for conn := conns.list.Front(); conn != nil; {
+		next := conn.Next()
+		_ = conn.Value.(net.Conn).Close()
+		conns.list.Remove(conn)
+		conn = next
+	}
+}
+
 // LRUConnsEntry is an entry in a LRUConns list.
 // LRUConnsEntry is an entry in a LRUConns list.
 type LRUConnsEntry struct {
 type LRUConnsEntry struct {
 	lruConns *LRUConns
 	lruConns *LRUConns

+ 10 - 0
psiphon/server/tunnelServer.go

@@ -3108,6 +3108,16 @@ func (sshClient *sshClient) runTunnel(
 			sshClient.sessionID)
 			sshClient.sessionID)
 	}
 	}
 
 
+	// Close any remaining port forward upstream connections in order to
+	// interrupt blocked reads.
+	sshClient.Lock()
+	udpgwChannelHandler := sshClient.udpgwChannelHandler
+	sshClient.Unlock()
+	if udpgwChannelHandler != nil {
+		udpgwChannelHandler.portForwardLRU.CloseAll()
+	}
+	sshClient.tcpPortForwardLRU.CloseAll()
+
 	waitGroup.Wait()
 	waitGroup.Wait()
 
 
 	sshClient.cleanupAuthorizations()
 	sshClient.cleanupAuthorizations()