客户端在任何响应 GCLB 之前断开连接

client disconnected before any response GCLB

我们在 GCLB 前面部署了我们的站点。

LB -> Cloud run -> APP ENGINE API 

Cloud 运行 正在托管一个 React 站点和 App Engine golang API。

12 小时后,我们通过 google 分析发现点击量开始下降,但流量几乎没有变化。

我们的假设是以某种方式“丢失”流量,我可以在日志 2 中看到主要问题。

  1. 404 包含旧站点组件的地址。
  2. 客户端在任何响应错误之前断开连接。

我可以理解 404 错误,它的缓存请求寻找旧的站点组件。

但我不明白客户端断开连接错误以及它是否与我们“丢失”的流量有关。

有什么关于如何分析我们“丢失”的流量的建议吗?

更新:

我发现了一些与客户端客户端断开连接错误的关联。

  1. requestUrl包含图片资源例如 images/zoom.png?v1.0

  2. 后端服务名称为空backend_service_name: "" 不知道它怎么会是空的,我映射了所有资源和主机

日志

{
  "insertId": "cs2fmdg2eo8nba",
  "jsonPayload": {
    "cacheId": "FRA-1209ea83",
    "@type": "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry",
    "statusDetails": "client_disconnected_before_any_response"
  },
  "httpRequest": {
    "requestMethod": "GET",
    "requestUrl": "https://travelpricedrops.com/images/aero.png?v1.0",
    "requestSize": "78",
    "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1",
    "remoteIp": "109.104.52.1",
    "referer": "https://travelpricedrops.com/passthru?tab=front&vert=flights&origin-iata=LEJ&destination-iata=JFK&departure-time=2021-12-26T11%3A00%3A00Z&cabin-class=economy&num-adults=1&num-youth=0&rental-duration=6&dta=48&return-time=2022-01-01T11%3A00%3A00Z&f=cf&fuid=1102&b=k&buid=1043",
    "cacheLookup": true,
    "latency": "0.071958s"
  },
  "resource": {
    "type": "http_load_balancer",
    "labels": {
      "zone": "global",
      "backend_service_name": "",
      "forwarding_rule_name": "tpd-int-https-ipv4",
      "target_proxy_name": "int-tpd-target-proxy-2",
      "url_map_name": "int-tpd",
      "project_id": "tpdrops"
    }
  },
  "timestamp": "2021-11-09T06:13:55.121455Z",
  "severity": "INFO",
  "logName": "projects/tpdrops/logs/requests",
  "trace": "projects/tpdrops/traces/13821ba38ae9e3191381f3f64b0a7b1a",
  "receiveTimestamp": "2021-11-09T06:13:55.343086132Z",
  "spanId": "a5ae86336a24bc32"
}

配置

**gcloud compute forwarding-rules describe tpd-int-https-ipv4**

IPAddress: 34.149.93.11
IPProtocol: TCP
creationTimestamp: '2021-08-30T11:49:06.047-07:00'
description: ''
fingerprint: CIAg3TcEb9Y=
id: '1815919129513727693'
kind: compute#forwardingRule
labelFingerprint: 42WmSpB8rSM=
loadBalancingScheme: EXTERNAL
name: tpd-int-https-ipv4
networkTier: PREMIUM
portRange: 443-443
selfLink: https://www.googleapis.com/compute/v1/projects/tpdrops/global/forwardingRules/tpd-int-https-ipv4
target: https://www.googleapis.com/compute/v1/projects/tpdrops/global/targetHttpsProxies/int-tpd-target-proxy-2

**gcloud compute backend-services describe tpd-prod-back**
affinityCookieTtlSec: 0
backends:
- balancingMode: UTILIZATION
  capacityScaler: 0.0
  group: https://www.googleapis.com/compute/v1/projects/tpdrops/regions/us-central1/networkEndpointGroups/tpd-front
cdnPolicy:
  cacheKeyPolicy:
    includeHost: true
    includeProtocol: true
    includeQueryString: true
  cacheMode: CACHE_ALL_STATIC
  clientTtl: 3600
  defaultTtl: 3600
  maxTtl: 86400
  negativeCaching: false
  requestCoalescing: true
  serveWhileStale: 86400
  signedUrlCacheMaxAgeSec: '0'
connectionDraining:
  drainingTimeoutSec: 0
creationTimestamp: '2021-10-25T04:09:29.908-07:00'
description: ''
enableCDN: true
fingerprint: 5FNZk6GXJTw=
iap:
  enabled: false
id: '6357784085114072710'
kind: compute#backendService
loadBalancingScheme: EXTERNAL
logConfig:
  enable: true
  sampleRate: 1.0
name: tpd-prod-back
port: 80
portName: http
protocol: HTTP
selfLink: https://www.googleapis.com/compute/v1/projects/tpdrops/global/backendServices/tpd-prod-back
sessionAffinity: NONE
timeoutSec: 30

**gcloud compute url-maps describe int-tpd**
creationTimestamp: '2021-08-29T06:08:35.918-07:00'
defaultService: https://www.googleapis.com/compute/v1/projects/tpdrops/global/backendServices/tpd-prod-back
fingerprint: trtG9xBMlvE=
hostRules:
- hosts:
  - acpt.travelpricedrops.com
  pathMatcher: path-matcher-2
- hosts:
  - int.travelpricedrops.com
  pathMatcher: path-matcher-1
- hosts:
  - api.acpt.travelpricedrops.com
  pathMatcher: path-matcher-3
- hosts:
  - api.int.travelpricedrops.com
  pathMatcher: path-matcher-4
- hosts:
  - api.travelpricedrops.com
  pathMatcher: path-matcher-5
- hosts:
  - travelpricedrops.com
  pathMatcher: path-matcher-6
id: '6018005644614187068'
kind: compute#urlMap
name: int-tpd
pathMatchers:
- defaultService: https://www.googleapis.com/compute/v1/projects/tpdrops/global/backendServices/tpd-acpt-back
  name: path-matcher-2
- defaultService: https://www.googleapis.com/compute/v1/projects/tpdrops/global/backendServices/tpd-int-http
  name: path-matcher-1
- defaultService: https://www.googleapis.com/compute/v1/projects/tpdrops/global/backendServices/tpd-api-acpt
  name: path-matcher-3
- defaultService: https://www.googleapis.com/compute/v1/projects/tpdrops/global/backendServices/tpd-api-int
  name: path-matcher-4
- defaultService: https://www.googleapis.com/compute/v1/projects/tpdrops/global/backendServices/tpd-api
  name: path-matcher-5
- defaultService: https://www.googleapis.com/compute/v1/projects/tpdrops/global/backendServices/tpd-prod-back
  name: path-matcher-6
selfLink: https://www.googleapis.com/compute/v1/projects/tpdrops/global/urlMaps/int-tpd


 **gcloud compute target-http-proxies describe int-tpd-target-proxy-2**
ERROR: (gcloud.compute.target-http-proxies.describe) Could not fetch resource:
 - The resource 'projects/tpdrops/global/targetHttpProxies/int-tpd-target-proxy-2' was not found

您的负载均衡器的配置看起来没问题;您在端口 443 上有一个 https-ssl-secured 前端指向端口 80 上的 http 后端,这意味着 SSL 在负载均衡器上解析并以纯 http 形式发送到您的后端。

您得到的错误意味着(根据 documentation)客户端在负载平衡器可以回复之前断开连接:

client_disconnected_before_any_response - The connection to the client was broken before the load balancer sent any response.

现在回答你的问题。

  1. 由于图像是由您的应用直接提供的(我没有看到任何主机路径规则另有说明)确保应用可以及时提供图像。将您的应用程序响应超时设置为 10 秒或更长时间,这应该可以解决问题。看看 this discussion 这可能对你很有用。 1.1 - 还有一个 configurable request timeout 用于云 运行 服务 - 您可以通过 运行 gcloud run services describe SERVICE_NAME

    进行检查
  2. 您提到的 backend_service_name: "" 字符串可能为空 - 无需担心 - 这是预期的行为。

此外,请查看 Backend service timeout Timeouts and retries in external load balancing,这也可能对您的案例有所帮助。

最后 - have a look at How to debug failed requests with client_disconnected_before_any_response.