首页 > 解决方案 > 在 Cloud Run 上通过 HTTP 侦听 gRPC 请求的问题

问题描述

我在 Cloud Run 上运行我的 gRPC 服务没有任何问题。但是今天,我意识到他们不再通过 HTTP 工作,包括很长时间没有变化的服务。

例外是The request :scheme header 'https' does not match the transport scheme 'http'."

那么,Cloud Run 方面是否有任何变化,或者我缺少什么?

更新:如果我更改代码以通过 HTTPS 接收请求,它们可能会起作用(尚未测试)。但是,这不是重点。他们之前运行没有任何问题。

Update2:我按照https://cloud.google.com/run/docs/quickstarts/build-and-deploy/c-sharp中的说明实现了 Program.cs 和 docker 文件,但这也不起作用。

Update3:与该示例项目相同。https://github.com/turgayozgur/dotnet-hello-world-grpc示例应用程序不期待 :scheme 标头上的 HTTPS。为什么即使 Cloud Run 和应用程序之间的请求不是 HTTPS 请求,云运行也会将该标头设置为 HTTPS?

类似问题: https ://github.com/linkerd/linkerd/issues/2401 https://www.gitmemory.com/issue/dotnet/aspnetcore/30532/787011248

标签: grpcgoogle-cloud-run

解决方案


这是一个对我有用的解决方法:

  1. 下载aspnetcore repo,我用v5所以git clone https://github.com/dotnet/aspnetcore.git && cd aspnetcore && git checkout tags/v5.0.5
  2. 找到文件/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs并注释掉第 244-250 行。如果不是 5.0.5 版,它是以 开头的代码块if (!ReferenceEquals(headerScheme, Scheme) &&,注释整个 if 块
  3. 构建项目 -./build.sh --configuration Release在项目的根目录中。它有一些错误,但我需要的文件已构建。
  4. 获取文件aspnetcore/artifacts/bin/Microsoft.AspNetCore.Server.Kestrel.Core/Release/net5.0/Microsoft.AspNetCore.Server.Kestrel.Core.dll并将其复制到具有以下 Dockerfile 的文件夹中:
FROM mcr.microsoft.com/dotnet/aspnet:5.0

COPY ./Microsoft.AspNetCore.Server.Kestrel.Core.dll /usr/share/dotnet/shared/Microsoft.AspNetCore.App/5.0.5/

有点痛苦,但我们用这个来支持 Cloud Run ......


推荐阅读