GRPC_WEB_FETCH_FAILED grpc network_error ai_generated true

内部错误: grpc-web: 获取失败

INTERNAL: grpc-web: Failed to fetch

ID: grpc/grpc-web-failed-to-fetch

其他格式: JSON · Markdown 中文 · English
90%修复率
85%置信度
1证据数
2024-03-15首次发现

版本兼容性

版本状态引入弃用备注
grpc-web 1.4.2 active
envoy 1.28.0 active
grpc-go 1.62.0 active
protobuf 25.3 active

根因分析

浏览器 CORS 策略或网络故障阻止 gRPC-Web 请求到达 Envoy 代理或 gRPC 服务器。

English

Browser CORS policy or network failure prevents gRPC-Web requests from reaching the Envoy proxy or gRPC server.

generic

官方文档

https://github.com/grpc/grpc-web/blob/master/doc/cors.md

解决方案

  1. Configure Envoy CORS filter to allow the origin, methods, and headers. Example Envoy config snippet:
      http_filters:
      - name: envoy.filters.http.cors
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.http.cors.v3.Cors
          allow_origin_string_match:
          - prefix: "https://myapp.example.com"
          allow_methods: "POST, OPTIONS"
          allow_headers: "content-type, x-grpc-web, x-user-agent"
          max_age: "86400"
      Then restart Envoy.
  2. Ensure the gRPC-Web client uses the correct URL (e.g., http://localhost:8080 instead of https://localhost:8080 if TLS is not set up) and that the Envoy proxy is running and reachable. Verify with curl: curl -v http://localhost:8080/your.service/Method

无效尝试

常见但无效的做法:

  1. 95% 失败

    Bypasses security but breaks in production and on other browsers; not a real fix.

  2. 90% 失败

    The error is not timeout-related; it's a pre-request fetch failure, so timeout changes have no effect.