0

First of all I find google's cloud docs lacking and somewhat incorrect a fair bit of the time.

I am attempting to connect from a cloud function to a cloud sql database and I have having endless issues.

Here is the connection error

"Internal error looking up Cloud SQL instance "project:region:database/.s.PGS"" Error: connect ENOENT /cloudsql/project:region:database/.s.PGSQL.5432 

I am able to connect to said database locally with the public ip address and code is all working fine, but when deployed it doesn't work at all.

What I have...

Project A - This has the database in australia-souteast1 region.
Project B - This has all the other logic, also in australia-southeast1

(the database is legacy, hence why its in a different project).

I have a cloud schedule task that triggers a pubsub, which inturn triggers the cloud function. This process works, and is logging what it should, this is also where I am seeing the can't connect error.

Connection host is /cloudsql/projectId:region:database (coppied from the cloud sql connection page, so I know that isn't the issue).

I have also enabled Cloud Sql API and Cloud Sql Admin Api on both Project A and Project B and still no luck.

I have also tried with the default service account by adding the Cloud Sql Client permission in Project B and then adding Project B's default service account into Project A with Cloud Sql Client permissions.

Failing that, I then created a new service account in Project B and gave it Owner permissions and then added that user to Project A with Owner permissions also, I am still getting this error.

I really have no clue now as to what is going on.

We have app engines on Project B connecting to Project A without any issues, I am really confused.

Here is the stack driver error Stack Driver Error

And my be connection details via an .env file enter image description here


UPDATE:

Changing the database to a different database instance in Project A seems to connect, so it is looking like it is possibly a problem with the database instance.

Database 1 is working and I can connect to.
Database 2 is the one that I can not get to work. Database 2 is a clone of Database 1

1 Answer 1

1

In this case, the docs are absolutely correct, but you are using the wrong filepath. The unix socket is located at /cloudsql/project:region:database/.s.PGSQL.5432, not /cloudsql/project:region:database/.s.PGS/.s.PGSQL.5432.

Sign up to request clarification or add additional context in comments.

8 Comments

ah bugger, I actually had a typeo there, i have updated the error. the cloud sql path i don't include the .s.PGSQL.5432 at all, i just have /cloudsql/projectId:region:database
Did the error change? You're posted stack still says "Cloud SQL instance "project:region:database/.s.PGS", which still indicates a typo.
im not adding any of those details to the connection host, i can only assume that it is happening at googles end. I also have noted that it seems to be only happening on the cloned database. I also created a new database and imported part of the database to check connection to, and that one works as well. all with the same code, just changing the database host
i have added some images with the stack driver errors and env file config
So I can't tell for sure, but you have a very long path for your unix socket. Is it over the unix socket length limit? (>108 characters?)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.