简体   繁体   中英

Nest.js API + Google Cloud Storage on Cloud Run every GET request to trigger "Stream error in the HTTP/2 framing layer" (POST requests work fine)

I created a Nest.js API service that has an endpoint to upload a file to a Google Bucket. Everything works perfectly locally and also when using the local Docker image. Once I deploy (successfully) on Cloud Run, all GET requests return "Error: Stream error in the HTTP/2 framing layer" from Insomnia. The rest of the endpoints (POST, etc.) works perfectly. I thought it was because I was using streams. Therefore, I switched to normal file upload, but it did not help.

I am not using HTTP/2 in Nest.js and I do not need it. I just need to upload a small file through the API.

I tried enabling HTTP/2 on Cloud Run. Did not help. I remove the stream implementation and use the normal "upload". Did not help.

Could you please suggest a course of action?

This error often appears when a server has HTTP/2 support however there is an intermediate reverse proxy that doesn't completely support HTTP/2 responses by the backend. So the client and server negotiate an upgrade to HTTP/2, but in between the get expression breaks things. Also the http/2 is always preferred when supported by both client and server. To avoid this error,you can try to disable it using below:

handle_setopt(http_version = 2) (2 is the value for CURL_HTTP_VERSION_1_1)

Cloud Run is an HTTP Request/Response design. This means that processing starts when you call the endpoint and ends when the endpoint returns.There is also a possibility as some APIs configurations and calling methods don't seem compatible with the latest HTTP version. The newer version of CURL will use this protocol by default and as a result will fail. This can create some rather confusing behavior because a script that works on one machine may not necessarily work on another by default means what is used unless you set another version. Thus, setting 1_1 as the protocol version required will override the default libcurl itself would use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM