Reputation: 8885
I have a Google Cloud Function that uses the java.net.http.HttpClient
to send a GET request to the URL https://userinfo-service-55555xyz-ew.a.run.app
(that is represting my Cloud Run Service).
Both the function and the run service are located in europe-west1
.
However the following exception is thrown when calling the logic for the GET request.
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 )
This is the Java code for the call:
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);
}
Excerpt 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 [email protected]:
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: [email protected]
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
Excerpt: 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: [email protected]
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
Upvotes: 0
Views: 456