GCP Cloud在标题前连接错误或断开连接/重置。重置原因:协议错误
我有一个与WebPack捆绑在一起的节点应用程序,我试图将其部署到云运行。为了能够在云运行中加载一个超过32 MB(设置限制)的文件,我将标题('Transfer-necoding':'bunked')添加到WebPack配置文件中。 (该文件是一个min.js文件,该文件是该网站的缩小版本,并在击中URL时加载)。
本地所有内容运行正常,但是当在云运行中部署此更改时,它会在部署应用程序后单击应用程序时会出现错误的错误:
(502错误)
“上游连接错误或脱离连接或在标题之前删除/重置。重置原因:协议错误:协议错误“
我已在部署中禁用了HTTP2端到端选项。
这是webpack文件,其中添加了标头
webpack.config.js
devserver:{
contentBase: path.resolve(__dirname, 'build'),
host: '0.0.0.0',
port: process.env.PORT || 8601,
sockPort: 'location',
disableHostCheck: true,
devServer: {
headers: {
'Transfer-encoding': 'chunked',
},
},
}
I have a node app bundled with webpack which I am trying to deploy to cloud run. In order to be able to load a file more than 32 MB (the set limit) in cloud run I added the header ('Transfer-encoding' : 'chunked') to the webpack config file. (The file is a min.js file ,the minified version of the website and is loaded upon hitting the url).
Locally everything runs fine but when this change is deployed on cloud run, it gives the follwoing error upon clicking on the app url after it is deployed:
(502 error)
"upstream connect error or disconnect/reset before headers. reset reason: protocol error"
I have disabled the http2 end-to-end option in deployment.
Here is the webpack file where the header is added
webpack.config.js
devServer: {
contentBase: path.resolve(__dirname, 'build'),
host: '0.0.0.0',
port: process.env.PORT || 8601,
sockPort: 'location',
disableHostCheck: true,
devServer: {
headers: {
'Transfer-encoding': 'chunked',
},
},
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根本原因
我早些时候检查了选项
使用http/2端到端
,如果您的容器是GRPC流媒体服务器或能够在HTTP/2 ClearText中直接处理请求,则使用使用使用。我是出于一些故障排除目的而做到的。选择
使用http/2端到端
并在云运行时部署服务后,通常需要一些时间才能将这些视线生效。因此,当您打开
使用http/2端到端
时,您可能不会预先看到故障。诸如 gcp云之类的故障在上游连接错误或标题之前断开/重置。重置原因:可能会出现协议错误。修复
修复,取消选择GCP控制台,导航到云运行 - >您的服务 - >编辑 - >连接选项卡 - >
使用http/2端到端
。然后选择“选项”
立即使用此修订
,然后单击 exploy 。现在,您的应用程序应如我所示,如预期的那样正常工作。
Root Cause
I had earlier checked the option
Use HTTP/2 end-to-end
that said Use if your container is a gRPC streaming server or is able to directly handle requests in HTTP/2 cleartext.I did that for some troubleshooting purposes. It often takes some time to take those seetings into effect after you select
Use HTTP/2 end-to-end
and Deploy your service on Cloud Run.So you might not see the failures upfront when you turn on
Use HTTP/2 end-to-end
. Failures such as gcp cloud run upstream connect error or disconnect/reset before headers. reset reason: protocol error might arise.Fix
To fix, unselect from GCP Console, navigate to Cloud Run -> Your Service -> Edit -> Connections Tab ->
Use HTTP/2 end-to-end
.Then choose the option
Serve this revision immediately
and click on Deploy.Now, your application should work properly as expected as shown in my case.
我实际上遇到了这个确切的错误,因为我正在用消息主体发送204响应。如果您为您,将状态更改为200或202。
I actually encountered this exact error because I was sending a 204 response with a message body. Change the status to 200 or 202 if that's the case for you.
我很聪明,并返回103个状态代码(出于某种原因)。这似乎使云功能中的过程的一部分混淆了,该过程停止了函数完成并返回了502。
将响应更改为202为我解决了问题。
I was being clever and returning an 103 status code (for some reason). That seems to have confused a part of the process in Cloud Functions which stopped the function completing and returned a 502.
Changing the response to a 202 solved the problem for me.
嗨,
我们对我们的云运行实例的调用有着非常相同的502响应:
我们的云运行服务提供了文档生成,其中JSON输入的属性被用作文档名称的一部分。我们的响应标题包含这样的标题条目:
我们的服务也在用西里尔字母写成的属性的国家 /地区运行。这给我们带来了问题。
我们找到了文件名的替代方法,该替代与用户的输入无关。
希望有帮助!
Hi,
we had the very same 502 response on calls to our Cloud Run instance, with the body:
Our Cloud Run service provides a document generation, where an attribute of the json input was used as part of the document name. Our response headers contained a header entry like this:
Our service also runs in countries with the attribute written in cyrillic letters. This caused the issue for us.
We found an alternative for the filename, which was independent of the input of the user.
Hope that helps!
当GCP中的服务试图返回需要http2协议的内容时,我遇到了这个错误
:
可以通过以下方式解决此问题:
返回一些httpstatus,因为http 1或1.1协议具有某些默认的httpstatus
在服务级别启用http2
启用GCP控制台端到端的HTTP2
I got this error when a service in GCP tries to return something which requires HTTP2 protocol
For ex:
This can be easily solved by :
Returning some HttpStatus, as http 1 or 1.1 protocol has some default HttpStatus
Enabling http2 at service level
Enabling http2 end-to-end from GCP Console
Defing it in nginx or ingress layer
当我在云运行中启用http/2时,我遇到了这个错误,我正在使用gcp
https://github.com/googleclodplatform/cloud-run-hello/tree/master/master
事实证明,默认Hello App不从GRPC服务器开始。启用HTTP/2意味着您的容器应支持GRPC,
我从GCP找到了GCP的旧Docker图像
https://cloud.google.com/api-网关/docs/get-started-cloud-run-grpc
我使用 grpcurl 请求
查找可用端点的
I got this error when I enabled http/2 in cloud run, I was using sample app provided by GCP
https://github.com/GoogleCloudPlatform/cloud-run-hello/tree/master
Turns out the default hello app doesn't start with GRPC server. Enabling http/2 means your container should support GRPC
I found an old docker image from GCP with GRPC
https://cloud.google.com/api-gateway/docs/get-started-cloud-run-grpc
I used grpcurl to make the request
To find available endpoints