1

I deployed my code on app engine with node js (flex environment).

config.json

{
  "GCLOUD_PROJECT": "XXXXXX",
  "DATA_BACKEND": "cloudsql",
  "MYSQL_USER": "XXXX",
  "MYSQL_PASSWORD": "XXXXX",
  "INSTANCE_CONNECTION_NAME": "XXXXXX:us-central1:XXXXX"
}

model-cloudsql.js

const options = {
  user: config.get('MYSQL_USER'),
  password: config.get('MYSQL_PASSWORD'),
  database: 'XXXXX'
};

if (config.get('INSTANCE_CONNECTION_NAME') && config.get('NODE_ENV') === 'production') {
  options.socketPath = `/cloudsql/${config.get('INSTANCE_CONNECTION_NAME')}`;
}
const connection = mysql.createConnection(options);

I am getting below error:

"Cannot enqueue Query after fatal error."

please provides any feedback on it.

GYaN
  • 2,327
  • 4
  • 19
  • 39

1 Answers1

0

It looks like the error "Cannot enqueue Query after fatal error." happens when you try to query a connection that encounter a fatal error during create. If we check out the mysqljs documentation, it recommends connecting with the following:

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'example.org',
  user     : 'bob',
  password : 'secret'
});

connection.connect(function(err) {
  if (err) {
    console.error('error connecting: ' + err.stack);
    return;
  }

  console.log('connected as id ' + connection.threadId);
});

As you can see, you need to pass along a callback function to handle any errors that may arise while you are attempting to connect. This callback function will print the error encountered to give you more info on why it failed to connect.

Additionally, you may be interested in this section on handling errors.

kurtisvg
  • 3,412
  • 1
  • 8
  • 24
  • thanks , but question is based on google cloud (App Engine/NodeJS) – Dinesh Kumar May 11 '18 at 04:09
  • @DineshKumar Nothing about the problem described in your question is specific to Google Cloud (or App Engine). You are trying to perform an operation on a connection that failed - if you want to find out why the connection failed, you will need to handle the failure as described above. – kurtisvg May 12 '18 at 23:26