grpc - 在 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
解决方案
这是一个对我有用的解决方法:
- 下载aspnetcore repo,我用v5所以
git clone https://github.com/dotnet/aspnetcore.git && cd aspnetcore && git checkout tags/v5.0.5
- 找到文件
/src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs
并注释掉第 244-250 行。如果不是 5.0.5 版,它是以 开头的代码块if (!ReferenceEquals(headerScheme, Scheme) &&
,注释整个 if 块 - 构建项目 -
./build.sh --configuration Release
在项目的根目录中。它有一些错误,但我需要的文件已构建。 - 获取文件
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 ......
推荐阅读
- android - 如何在基于 tensorflow lite 对象检测 android 的应用程序中将文本添加到语音中?
- vue.js - 如何使用 vue-google-api 包获取 access_token 以便在 Google api 中进一步使用?
- python - python 3中的lxml:包含tostring(method ='html')无法识别的脚本元素和换行符的标签/元素
- python - Pandas 数据框的 3D 图
- python - TensorFlow CondaVerificationError - 将 Pip 与 Conda 混合
- java - 在无向图中找到两个节点之间断开连接的最小权重
- python - 是否有动态调度系统可以更好地实施基于订阅的支付系统?
- sql - 每个组内的 SQL 连接
- php - ORDER BY 和 WHERE 变量和 LIMIT
- reactjs - Reactjs 更新祖父母状态