chore: reduce process lookup attempts when process not exist #613

This commit is contained in:
gVisor bot 2023-06-08 18:07:56 +08:00
parent b183183fbc
commit c413e58932

View file

@ -540,7 +540,7 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) {
defer configMux.RUnlock() defer configMux.RUnlock()
var ( var (
resolved bool resolved bool
processFound bool attemptProcessLookup = true
) )
if node, ok := resolver.DefaultHosts.Search(metadata.Host, false); ok { 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()) { if attemptProcessLookup && !findProcessMode.Off() && (findProcessMode.Always() || rule.ShouldFindProcess()) {
srcPort, err := strconv.ParseUint(metadata.SrcPort, 10, 16) attemptProcessLookup = false
srcPort, _ := strconv.ParseUint(metadata.SrcPort, 10, 16)
uid, path, err := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(srcPort)) uid, path, err := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(srcPort))
if err != nil { if err != nil {
log.Debugln("[Process] find process %s: %v", metadata.String(), err) 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.Process = filepath.Base(path)
metadata.ProcessPath = path metadata.ProcessPath = path
metadata.Uid = uid metadata.Uid = uid
processFound = true
} }
} }