Fezekile Plaatyi
Fezekile Plaatyi

Reputation: 51

How to solve error: Error: connect ETIMEDOUT at PoolConnection.Connection._handleConnectTimeout?

I am using Google Cloud App Engine with Nodejs And MYSQL. I am ensouting the error bellow, please help. I did some research but nothing is similar to be working, the connection.release() and connection.end() The error message shows as bellow:

{ Error: connect ETIMEDOUT at PoolConnection.Connection._handleConnectTimeout 
(/app/node_modules/mysql/lib/Connection.js:411:13) at Object.onceWrapper
 (events.js:286:20) at Socket.emit (events.js:198:13) at Socket._onTimeout (net.js:442:8) 
at ontimeout (timers.js:436:11) at tryOnTimeout
 (timers.js:300:5) at listOnTimeout (timers.js:263:5) at Timer.processTimers (timers.js:223:10)

The connection is created this way:

//create connection
var connection = mysql.createPool
({
  host     : 'host_here', 
  user     : 'root',
  connectionLimit : 1000, 
  password : 'the_password',
  database : 'the_dbname',
  port : 3306, 
  charset : 'utf8mb4'
});



global.db = connection;

The on my route I do the following which results to above-mentioned error:

db.getConnection(function(err, connection) 
{
    if (err) 
    {
         console.log("Connection ERROR")
         console.log(err);
    }
    else 
    {
       connection.query('SELECT * FROM `my_table_name`', function (error, results, fields) 
       {
            // When done with the connection, release it.
            connection.release();

            // Handle error after the release.
            if (error) 
            {
               console.log("ERROR")
               console.log(error);
            }
            if (results)
            {
               console.log("Results")
               console.log(results)
            }
            if(fields)
            {
               console.log("FIELDS")
               console.log(fields)
            }
        });
     }
});

Upvotes: 4

Views: 15429

Answers (1)

Stefan G.
Stefan G.

Reputation: 938

  1. Please make sure that your Cloud SQL API is activated.
  2. Make sure that your Cloud SQL Instance is a Second Generation one.

Here you have a step-by-step Node.JS in App Engine Flex connection to a CloudSQL instance.

Let me know.

Upvotes: 2

Related Questions