GCP Cloud在标题前连接错误或断开连接/重置。重置原因:协议错误

发布于 2025-02-06 20:31:25 字数 678 浏览 3 评论 0原文

我有一个与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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

牵你的手,一向走下去 2025-02-13 20:31:25

根本原因

我早些时候检查了选项使用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.

enter image description here

Fix

To fix, unselect from GCP Console, navigate to Cloud Run -> Your Service -> Edit -> Connections Tab -> Use HTTP/2 end-to-end.

enter image description here

Then choose the option Serve this revision immediately and click on Deploy.

enter image description here

Now, your application should work properly as expected as shown in my case.

enter image description here

单身情人 2025-02-13 20:31:25

我实际上遇到了这个确切的错误,因为我正在用消息主体发送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.

围归者 2025-02-13 20:31:25

我很聪明,并返回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.

ゞ花落谁相伴 2025-02-13 20:31:25
TLDR: Check your response header for special characters.

嗨,

我们对我们的云运行实例的调用有着非常相同的502响应:

upstream connect error or disconnect/reset before headers. reset reason: protocol error

我们的云运行服务提供了文档生成,其中JSON输入的属性被用作文档名称的一部分。我们的响应标题包含这样的标题条目:

Content-Disposition: attachment; filename=<the-attribute-value>.pdf

我们的服务也在用西里尔字母写成的属性的国家 /地区运行。这给我们带来了问题。

我们找到了文件名的替代方法,该替代与用户的输入无关。

希望有帮助!

TLDR: Check your response header for special characters.

Hi,

we had the very same 502 response on calls to our Cloud Run instance, with the body:

upstream connect error or disconnect/reset before headers. reset reason: protocol error

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:

Content-Disposition: attachment; filename=<the-attribute-value>.pdf

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!

千纸鹤带着心事 2025-02-13 20:31:25
upstream connect error or disconnect/reset before headers. reset reason: protocol error

当GCP中的服务试图返回需要http2协议的内容时,我遇到了这个错误

public ResponseEntity<List<AppDto>> fun (){
...
return new ResponseEntity<List<AppDto>> (response);
}

可以通过以下方式解决此问题:

  1. 返回一些httpstatus,因为http 1或1.1协议具有某些默认的httpstatus

     公共响应态度&lt; list&lt; appdto&gt;&gt;&gt;乐趣 (){
        ...
        返回新的响应性&lt; list&lt; appdto&gt;&gt; (响应,httpstatus.ok);
        }
     
  2. 在服务级别启用http2

     服务器:
      http2:
        启用:true
     
  3. 启用GCP控制台端到端的HTTP2

  4. 将其在nginx或Ingress layer中进行防御

      nginx.ingress.kubernetes.io/proxy-http-version:“ 1.1”
     
upstream connect error or disconnect/reset before headers. reset reason: protocol error

I got this error when a service in GCP tries to return something which requires HTTP2 protocol

For ex:

public ResponseEntity<List<AppDto>> fun (){
...
return new ResponseEntity<List<AppDto>> (response);
}

This can be easily solved by :

  1. Returning some HttpStatus, as http 1 or 1.1 protocol has some default HttpStatus

    public ResponseEntity<List<AppDto>> fun (){
        ...
        return new ResponseEntity<List<AppDto>> (response, HttpStatus.OK);
        }
    
  2. Enabling http2 at service level

    server:
      http2:
        enabled:true
    
  3. Enabling http2 end-to-end from GCP Console

  4. Defing it in nginx or ingress layer

    nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
    
烂柯人 2025-02-13 20:31:25

当我在云运行中启用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 请求

grpcurl -proto bookstore.proto -H "Authorization: Bearer $(gcloud auth print-identity-token)" ur.cloud.run.app:443 endpoints.examples.bookstore.Bookstore/ListShelves

查找可用端点的

grpcurl -proto bookstore.proto -H "Authorization: Bearer $(gcloud auth print-identity-token)" ur.cloud.run.app:443 describe

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

grpcurl -proto bookstore.proto -H "Authorization: Bearer $(gcloud auth print-identity-token)" ur.cloud.run.app:443 endpoints.examples.bookstore.Bookstore/ListShelves

To find available endpoints

grpcurl -proto bookstore.proto -H "Authorization: Bearer $(gcloud auth print-identity-token)" ur.cloud.run.app:443 describe
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文