Strapi + Cloud SQL for MySQL on Google App Engine - Server wasn't able to start properly Error: getaddrinfo EAI_AGAIN
Asked Answered
N

1

6

I'm trying to start my Strapi app into Google App Engine, I did deployed successfully, but I keep getting this error on the logs:

Server wasn't able to start properly Error: getaddrinfo EAI_AGAIN /cloudsql/connectionName

Error Log:

error logs

I followed the instructions of deployment, but maybe something is missing, is like my app can't establish the connection with my Cloud SQL for MySQL database.

This is my .yaml file:

runtime: nodejs12

instance_class: F2

env_variables:
  HOST: '0.0.0.0'
  NODE_ENV: 'production'
  DATABASE_NAME: 'test'
  DATABASE_USERNAME: '***'
  DATABASE_PASSWORD: '***'
  INSTANCE_CONNECTION_NAME: '***'

beta_settings:
  cloud_sql_instances: '***'

module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'mysql',
        host: `/cloudsql/${env('INSTANCE_CONNECTION_NAME')}`,
        database: env('DATABASE_NAME'),
        username: env('DATABASE_USERNAME'),
        password: env('DATABASE_PASSWORD'),
      },
    },
  },
});

If someone knows about this and can help me I will appreciate it.

Nickeliferous answered 4/5, 2021 at 22:41 Comment(0)
U
7

After reviewing their official docs and GitHub issue, it turns out that what works properly when connecting via Unix Socket on Cloud SQL is to change host to socketPath, contrary to what's currently written which is socket (don't know why it doesn't). I tested and it works on v3.6.1.

After following their deployment guide, install mysql driver on your project:

yarn add mysql

Then, change host to socketPath:

module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: 'mysql',
        socketPath: `/cloudsql/${env('INSTANCE_CONNECTION_NAME')}`,
        database: env('DATABASE_NAME'),
        username: env('DATABASE_USERNAME'),
        password: env('DATABASE_PASSWORD'),
      },
    },
  },
});

Then to manage your project, go to the administration panel at /admin of your GAE URL.

Uralaltaic answered 5/5, 2021 at 6:0 Comment(1)
Thanks @Dondi, I just had to change host to socketPath.Chlortetracycline

© 2022 - 2024 — McMap. All rights reserved.