connect ETIMEDOUT 10.x.x.x:5432 in TCPConnectWrap.afterConnect means the initial TCP SYN packet is timing out at the network layer before a 3-way handshake with PostgreSQL can complete. Here are the answers to your specific questions and what to check to isolate the drop:
- Does the VPC connector need to use the same VPC network as the Cloud SQL private IP?
Yes. Unless you configured Cloud SQL with Private Service Connect (PSC), Cloud SQL private IP uses Private Services Access (PSA), which creates a VPC Network Peering (servicenetworking-googleapis-com) between a single VPC network and Google’s service producer VPC. Because VPC Network Peering is non-transitive, vpc-connector-1 must be attached to the exact same VPC network (or Shared VPC host network) that your Cloud SQL instance is peered with. If vpc-connector-1 is in vpc-a and Cloud SQL is peered with vpc-b, traffic will time out even if vpc-a and vpc-b are peered with each other.
Compare the VPC network on both resources to confirm they match:
gcloud compute networks vpc-access connectors describe vpc-connector-1 \
--region=us-central1 \
--format="yaml(network, ipCidrRange, subnet, state)"
gcloud sql instances describe my-postgres-db \
--format="yaml(settings.ipConfiguration.privateNetwork, ipAddresses)"
(Note: You can also use Direct VPC egress with --network and --subnet instead of a Serverless VPC Access connector, provided it attaches to that same VPC network.)
- Do I need to configure Cloud Run VPC egress explicitly?
Not if 10.x.x.x is a standard RFC 1918 address. When you specify --vpc-connector, Cloud Run defaults to --vpc-egress=private-ranges-only, which automatically routes all RFC 1918 destinations (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) through the connector. You only need --vpc-egress=all-traffic if your Cloud SQL PSA range uses non-RFC 1918 space (such as 100.64.0.0/10 or privately used public IPs).
- Could Private Services Access be causing the timeout?
Yes - if both resources are already on the same VPC network, a PSA routing or firewall issue is the most likely cause:
-
Missing return route to the connector /28 subnet: If vpc-connector-1 was created using a non-RFC 1918 /28 range (for example, 100.64.0.0/10), Google’s peered Cloud SQL producer network won’t learn that route by default and return SYN-ACK packets will drop. Make sure servicenetworking-googleapis-com has custom route export enabled and that the PSA peering route covering 10.x.x.x exists in your VPC:
gcloud compute routes list \
--filter="network:<YOUR_VPC_NETWORK> AND nextHopPeering:servicenetworking-googleapis-com"
gcloud compute networks peerings update servicenetworking-googleapis-com \
--network=<YOUR_VPC_NETWORK> \
--export-custom-routes
-
VPC egress firewall rules: Ingress firewall rules in your VPC don’t apply to traffic entering the Cloud SQL producer network, but an explicit egress deny rule in your VPC can block traffic leaving the connector’s /28 range (or network tag serverless-vpc-access) toward 10.x.x.x:5432.
-
Verify the exact drop point with a Connectivity Test: Pick an IP inside your VPC connector’s /28 CIDR range and test reachability to 10.x.x.x:5432:
gcloud network-management connectivity-tests create cloudrun-to-sql \
--source-network=projects/[PROJECT_ID]/global/networks/<YOUR_VPC_NETWORK> \
--source-ip-address=<IP_FROM_CONNECTOR_28_RANGE> \
--destination-ip-address=10.x.x.x \
--destination-port=5432 \
--protocol=TCP
gcloud network-management connectivity-tests describe cloudrun-to-sql \
--format="yaml(reachabilityDetails)"
- If I connect directly to 10.x.x.x:5432, do I still need --add-cloudsql-instances?
No. --add-cloudsql-instances starts the built-in Cloud SQL Auth Proxy inside Cloud Run and exposes a Unix domain socket at /cloudsql/[PROJECT_ID]:us-central1:my-postgres-db. Because your app is connecting directly to 10.x.x.x:5432 over TCP (DB_HOST=10.x.x.x), it bypasses that Unix socket completely, so neither --add-cloudsql-instances nor roles/cloudsql.client is used unless you switch your app to connect via the /cloudsql/... socket or use IAM database authentication.