grpc 服务器端流式传输失败带有子请求 CORS 错误

问题描述

我能够使用 grpc-web 实现一元调用,但服务器端流媒体无法按预期工作。 首次打开页面时,会调用 CreateStream 并按预期工作。网络选项卡如下所示:(有预检响应但未显示在屏幕截图中)

enter image description here

这是 CreateStream 200 的详细信息:

enter image description here

大约1分30-40秒后,会出现这个错误

enter image description here

发生该错误时将有另一个待处理的 CreateStream:

enter image description here

我的 envoy.yaml 看起来像这样:

static_resources:
  listeners:
  - name: listener_0
    address: 
      socket_address: { address: 0.0.0.0,port_value: 30800 }
    filter_chains:
    - filters:
      - name: envoy.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.httpconnectionManager
          codec_type: auto
          stat_prefix: ingress_http
          stream_idle_timeout: 0s
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match: { prefix: "/auth." }
                route: 
                  cluster: auth_service
                  max_grpc_timeout: 0s
              - match: { prefix: "/name_of_service." }
                route: 
                  cluster: stream_service
                  timeout: 0s
                  max_grpc_timeout: 0s
              cors:
                allow_origin_string_match:
                - prefix: "*"
                allow_methods: GET,PUT,DELETE,POST,OPTIONS
                allow_headers: access-control-allow-origin,keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,access-token,token,authorize-token,x-site-type,x-origin,x-pin-token,grpc-timeout
                expose_headers: custom-header-1,grpc-status,grpc-message
          http_filters:
          - name: envoy.filters.http.grpc_web
          - name: envoy.filters.http.cors
          - name: envoy.filters.http.router

错误总是每 1 分 30/40 秒发生一次。这意味着如果我不关闭页面,控制台中的红色错误消息会很多。 我也试过在客户方面设置最后期限,但没有用。如何修复此 CORS 错误?我没有看过 cloudflare,因为我不知道要看什么,而且如果 cloudflare 是问题,为什么一元调用和第一个服务器流调用有效? 谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)