Friday, February 24, 2017

[google-cloud-sql-discuss] Cloud SQL Proxy no longer working in App Engine environment


Sometime in the past few weeks an issue with Cloud SQL started to occur with the App Engine's Cloud SQL Proxy. I get the following error in the App Engine logs:

error when connecting to db: { Error: connect ECONNREFUSED 127.0.0.1:3306

The app works on my local machine with Cloud SQL Proxy, as does the counterpart app in Compute Cluster. It used to work in App Engine, too. I double checked the App Engine user's credentials are set to Editor.  I noticed that recently the App Engine parameter vm:true has been deprecated in favor of env: flex. I tried it both ways, with the same result. The following shows how I am connecting in Node.js:

var connection;

function handleDisconnect() {
  connection = mysql.createConnection({
    user: process.env.MYSQL_USER,
    password: process.env.MYSQL_PASSWORD,
    socketPath: process.env.MYSQL_SOCKET_PATH,
    database: process.env.MYSQL_DATABASE
  });                                             // Recreate the connection, since
                                                  // the old one cannot be reused.

  connection.connect(function(err) {              // The server is either down
    if(err) {                                     // or restarting (takes a while sometimes).
      console.log('error when connecting to db:', err);
      setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
    }                                     // to avoid a hot loop, and to allow our node script to
  });                                     // process asynchronous requests in the meantime.
                                          // If you're also serving http, display a 503 error.
  connection.on('error', function(err) {
    console.log('db error', err);
    if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
      handleDisconnect();                         // lost due to either server restart, or a
    } else {                                      // connnection idle timeout (the wait_timeout
      throw err;                                  // server variable configures this)
    }
  });
}

handleDisconnect();

I have the connection string as follows:
  INSTANCE_CONNECTION_NAME: /cloudsql/cybers-cafe:us-east1:cybers-cafe
and under beta_settings:
  cloud_sql_instances: cybers-cafe:us-east1:cybers-cafe

I also tried restarting the SQL server. It is in us-east1 and the instances are in us-east1-b/c.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/6c45aea8-8bc2-433d-ad53-7a7380169b1d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment