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

Interrupt port forwards blocked on upstream reads

Rod Hynes 4 месяцев назад
Родитель
Сommit
bb9614e7ec
2 измененных файлов с 23 добавлено и 0 удалено
  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.
 type LRUConnsEntry struct {
 	lruConns *LRUConns

+ 10 - 0
psiphon/server/tunnelServer.go

@@ -3108,6 +3108,16 @@ func (sshClient *sshClient) runTunnel(
 			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()
 
 	sshClient.cleanupAuthorizations()