Cloud Run can't connect to Cloud SQL through SocketFactory

9 views
Skip to first unread message

Khoa Trần Ngọc

unread,
Aug 30, 2021, 5:09:40 PMAug 30
to gce-discussion
I'm trying to connect Cloud Run service to a Cloud SQL instance.
I follow this guide with Public IP option: https://cloud.google.com/sql/docs/mysql/connect-run

This is my permission setup:
1. Add Cloud SQL Client role to Default compute service account
2. Add properly Cloud SQL connections when deploy Cloud Run service

This is my Spring Boot data source configuration:
Screen Shot 2021-08-31 at 12.45.57 AM.png

I already added dependencies for gradle project:

implementation 'mysql:mysql-connector-java:8.0.25'
implementation 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.3.2'


Result:
The application keep starting and shutdown. I added log bellow.

Question:
What happen with my set up? Why Cloud Run service can't connect to Cloud SQL?
I tried connect to Cloud SQL though proxy and it works properly.

2021-08-31 00:46:37.291 ICT
2021-08-30 17:46:37.288 INFO 1 --- [ main] c.k.b.c.f.FacebookConnectorApplication : Starting FacebookConnectorApplication using Java 11.0.11 on localhost with PID 1 (/app/classes started by root in /)
Default
2021-08-31 00:46:37.291 ICT
2021-08-30 17:46:37.291 INFO 1 --- [ main] c.k.b.c.f.FacebookConnectorApplication : The following profiles are active: cloud
Default
2021-08-31 00:46:40.916 ICT
2021-08-30 17:46:40.916 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
Default
2021-08-31 00:46:40.986 ICT
2021-08-30 17:46:40.986 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
Default
2021-08-31 00:46:40.986 ICT
2021-08-30 17:46:40.986 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.48]
Default
2021-08-31 00:46:41.207 ICT
2021-08-30 17:46:41.207 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
Default
2021-08-31 00:46:41.207 ICT
2021-08-30 17:46:41.207 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3797 ms
Default
2021-08-31 00:46:43.779 ICT
2021-08-30 17:46:43.777 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariCP - Starting...
Default
2021-08-31 00:46:44.008 ICT
2021-08-30 17:46:44.008 INFO 1 --- [ main] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [xxxx:asia-southeast1:xxxxx] via SSL socket.
Default
2021-08-31 00:46:44.008 ICT
2021-08-30 17:46:44.008 INFO 1 --- [ main] c.g.cloud.sql.core.CoreSocketFactory : First Cloud SQL connection, generating RSA key pair.
Debug
2021-08-31 00:46:44.280 ICT
Container Sandbox: Unsupported syscall setsockopt(0x5a,0x1,0xc,0x3e06596abbbc,0x4,0x7). It is very likely that you can safely ignore this message and that this is not the cause of any error you might be troubleshooting. Please, refer to https://gvisor.dev/c/linux/amd64/setsockopt for more information.
Default
2021-08-31 00:46:47.212 ICT
2021-08-30 17:46:47.212 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariCP - Start completed.
Default
2021-08-31 00:46:47.380 ICT
2021-08-30 17:46:47.379 INFO 1 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [xxxxx:asia-southeast1:xxxxx] via SSL socket.
Default
2021-08-31 00:46:47.505 ICT
2021-08-30 17:46:47.504 INFO 1 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [xxxxx:asia-southeast1:xxxxx] via SSL socket.
Default
2021-08-31 00:46:47.576 ICT
2021-08-30 17:46:47.576 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
Default
2021-08-31 00:46:47.591 ICT
2021-08-30 17:46:47.591 INFO 1 --- [ main] c.k.b.c.f.FacebookConnectorApplication : Started FacebookConnectorApplication in 11.797 seconds (JVM running for 12.96)
Default
2021-08-31 00:46:47.684 ICT
2021-08-30 17:46:47.684 INFO 1 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [psychic-era-313204:asia-southeast1:chat-bot] via SSL socket.
Error
2021-08-31 00:46:47.807 ICT
POST5031.19 KB13.3 sfacebookexternalua xxxxxx
Error
2021-08-31 00:46:48.513 ICT
POST5000 B0 msfacebookexternaluaxxxxxx
Error
2021-08-31 00:46:49.163 ICT
POST5000 B0 msfacebookexternalua xxxxxx
Default
2021-08-31 00:46:49.825 ICT
2021-08-30 17:46:49.825 INFO 1 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariCP - Shutdown initiated...
Reply all
Reply to author
Forward
0 new messages