簡體   English   中英

Google Cloud Function 無法調用 Cloud Function 服務,因為 jdk.internal.net.http.HttpClientImpl 中存在協議錯誤

[英]Google Cloud Function can't call Cloud Function Service because of protocol error in jdk.internal.net.http.HttpClientImpl

我有一個谷歌雲 Function,它使用java.net.http.HttpClient向 URL https://userinfo-service-55555xyz-ew.a.run.app發送 GET 請求(即重新啟動我的 Cloud Run 服務) .

function 和運行服務都位於europe-west1

但是,在調用 GET 請求的邏輯時拋出以下異常。

java.io.IOException: Received RST_STREAM: Protocol error

at jdk.internal.net.http.HttpClientImpl.send ( jdk/internal.net.http/HttpClientImpl.java:565 )
at jdk.internal.net.http.HttpClientFacade.send ( jdk/internal.net.http/HttpClientFacade.java:119 )
at com.myapp.functions.UserInit.callUserInfoService ( com/myapp.functions/UserInit.java:49 )
at com.myapp.functions.UserInit.service ( com/myapp.functions/UserInit.java:36 )

這是呼叫的 Java 代碼:

    private void callUserInfoService(String userId, String email) throws IOException, InterruptedException {
        String url = this.getUserInfoUrl() + "/init?auth0Id=" + userId + "&email=" + email;
        System.out.println("UserInfo URL used: " + url);

        var getRequest = java.net.http.HttpRequest.newBuilder().uri(URI.create(url)).GET().build();

        // Send the sendHttpRequest using the client
        var getResponse = client.send(getRequest, BodyHandlers.ofString());

        System.out.println("Received code " + getResponse.statusCode() + " from url " + url);
    }

摘錄gcloud run services describe userinfo-service --region=europe-west1

➜  cloud-functions git:(master) ✗ gcloud run services describe userinfo-service --region=europe-west1
✔ Service userinfo-service in region europe-west1
 
URL:     https://userinfo-service-55555xyz-ew.a.run.app
Ingress: all
Traffic:
  100% LATEST (currently userinfo-service-00001-qit)
 
Last updated on 2022-04-26T12:39:53.800502Z by falke2088@gmail.com:
  Revision userinfo-service-00001-qit
  Image:             eu.gcr.io/myapp/userinfo-service:95b5e56f-0162-4ac4-b5be-66f272884bb6
  Port:              8080
  Memory:            512Mi
  CPU:               1
  Service account:   981444444-compute@developer.gserviceaccount.com
  Env vars:
    LOG_LEVEL        debug
    SQL_CONNECTION   10.113.160.3
    SQL_DATABASE     db
    SQL_PASSWORD     test
    SQL_USER         test
  Concurrency:       10
  Min Instances:     1
  Max Instances:     2
  Timeout:           3000s
  VPC connector:
    Name:            cloud-run-connector
    Egress:          private-ranges-only

摘錄: gcloud functions describe user-init --region=europe-west1

➜  cloud-functions git:(master) ✗ gcloud functions describe user-init --region=europe-west1
availableMemoryMb: 4096
buildId: 837b8cb5-8f01-49e6-96a6-15f344c36c1e
buildName: projects/98175493814/locations/europe-west1/builds/837b8cb5-8f01-49e6-96a6-15f344c36c1e
dockerRegistry: CONTAINER_REGISTRY
entryPoint: com.myapp.functions.UserInit
environmentVariables:
  HOOK_KEY: f0ec5d68-ceff-4293-8a34-ec08a0dcd124
  USERINFO_SERVICE_URL: https://userinfo-service-55555xyz-ew.a.run.app
httpsTrigger:
  securityLevel: SECURE_ALWAYS
  url: https://europe-west1-myapp.cloudfunctions.net/user-init
ingressSettings: ALLOW_ALL
labels:
  deployment-tool: cli-gcloud
name: projects/myapp/locations/europe-west1/functions/user-init
runtime: java11
serviceAccountEmail: myapp@appspot.gserviceaccount.com
sourceUploadUrl: https://storage.googleapis.com/uploads-123543534.europe-west1.cloudfunctions.appspot.com/679c703d-b788-45a0-a8fc-4347f08d7f7c.zip
status: ACTIVE
timeout: 60s
updateTime: '2022-04-26T13:12:19.064Z'
versionId: '7'
vpcConnector: projects/myapp/locations/europe-west1/connectors/cloud-run-connector
vpcConnectorEgressSettings: ALL_TRAFFIC

我現在使用OkHttp3庫並且它可以工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM