0

The following code is to issue mysql query with Firebase Cloud Functions.

The code works when running on the local machine. ( $ firebase serve )
But when running on the Google Cloud Platform, the error ETIMEDOUT occur. ( $ firebase deploy )

I want you to tell me the possible causes.

NOTE
- Cloud Functions runtime config is Node.js 8 and my local env is also Node.js 8.0.0

Code:

const mysql = require('mysql')
const pool = mysql.createPool({
  host: '10.20.30.40',
  user: 'user',
  password: 'pass',
  database: 'db',
  connectTimeout : 10000
})

pool.query('SELECT * FROM table', (error, rows, fields) => {
  if (error) {
    console.error(error)
    throw error
  }

  console.log('The solution is: ', rows)

  pool.end()
})

Error:

{ Error: connect ETIMEDOUT
    at PoolConnection.Connection._handleConnectTimeout (/srv/node_modules/mysql/lib/Connection.js:411:13)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at Socket._onTimeout (net.js:420:8)
    at ontimeout (timers.js:482:11)
    at tryOnTimeout (timers.js:317:5)
    at Timer.listOnTimeout (timers.js:277:5)
    --------------------
    at Protocol._enqueue (/srv/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/srv/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at PoolConnection.connect (/srv/node_modules/mysql/lib/Connection.js:118:18)
    at Pool.getConnection (/srv/node_modules/mysql/lib/Pool.js:48:16)
    at Pool.query (/srv/node_modules/mysql/lib/Pool.js:202:8)
    at Promise (/srv/lib/modules/myCellar.js:32:14)
    at new Promise (<anonymous>)
    at Object.exports.get.uid [as get] (/srv/lib/modules/myCellar.js:31:12)
    at Object.<anonymous> (/srv/lib/index.js:14:36)
    at Generator.next (<anonymous>)
  errorno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',
  fatal: true }
kusumoto_teruya
  • 2,415
  • 4
  • 23
  • 38

0 Answers0