Kaynağa Gözat

Feature #JiraBug29304 【私有发版v8.5性能测试】eBPF探针运行中,启动抓包工具抓web数据,退出抓包工具一段时间后探针挂掉,日志中报panic错误

Tom 1 yıl önce
ebeveyn
işleme
c8a2aa4f35
1 değiştirilmiş dosya ile 14 ekleme ve 2 silme
  1. 14 2
      ebpftracer/l7/http.go

+ 14 - 2
ebpftracer/l7/http.go

@@ -35,9 +35,21 @@ func ParseHttpHost(payload []byte) (string, string, string, uint16) {
 		uri = append(uri, []byte("...")...)
 	}
 
-	hostStart := bytes.Index(rest, []byte("Host:")) + len("Host:")
+	//hostStart := bytes.Index(rest, []byte("Host:")) + len("Host:")
+	hostHeader := "Host:"
+	hostIdx := bytes.Index(rest, []byte(hostHeader))
+	if hostIdx == -1 {
+		return string(method), string(uri), "", 0
+	}
+	hostStart := hostIdx + len(hostHeader)
 	hostEnd := bytes.Index(rest[hostStart:], []byte("\r\n"))
-	hostPort := string(bytes.TrimSpace(rest[hostStart : hostStart+hostEnd]))
+	var hostPortBts []byte
+	if hostEnd == -1 {
+		hostPortBts = rest[hostStart:]
+	} else {
+		hostPortBts = rest[hostStart : hostStart+hostEnd]
+	}
+	hostPort := string(bytes.TrimSpace(hostPortBts))
 	hostParts := strings.Split(hostPort, ":")
 	host := hostParts[0]
 	port := uint16(80) // Default port