From c413e58932430beffa13fec3a152922bd89a2307 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Thu, 8 Jun 2023 18:07:56 +0800 Subject: [PATCH] chore: reduce process lookup attempts when process not exist #613 --- tunnel/tunnel.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index cbbcaa75..e375f656 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -539,8 +539,8 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) { configMux.RLock() defer configMux.RUnlock() var ( - resolved bool - processFound bool + resolved bool + attemptProcessLookup = true ) if node, ok := resolver.DefaultHosts.Search(metadata.Host, false); ok { @@ -564,8 +564,9 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) { }() } - if !findProcessMode.Off() && !processFound && (findProcessMode.Always() || rule.ShouldFindProcess()) { - srcPort, err := strconv.ParseUint(metadata.SrcPort, 10, 16) + if attemptProcessLookup && !findProcessMode.Off() && (findProcessMode.Always() || rule.ShouldFindProcess()) { + attemptProcessLookup = false + srcPort, _ := strconv.ParseUint(metadata.SrcPort, 10, 16) uid, path, err := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(srcPort)) if err != nil { log.Debugln("[Process] find process %s: %v", metadata.String(), err) @@ -573,7 +574,6 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) { metadata.Process = filepath.Base(path) metadata.ProcessPath = path metadata.Uid = uid - processFound = true } }