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.

3
  • Possibly related stackoverflow.com/q/37619977/5320906 Commented Mar 26, 2018 at 7:40
  • As per snakecharmerb's linked question, this is usually related to improper connection management. Have you been able to solve this? Are you getting this error on every run? Commented Apr 5, 2018 at 15:50
  • Yes, if you have any solution, please provide me Commented Apr 7, 2018 at 4:46

1 Answer 1

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.

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

2 Comments

thanks , but question is based on google cloud (App Engine/NodeJS)
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.