#nodejs #2ndGen Error: connect ETIMEDOUT

2,809 views
Skip to first unread message

Lekooa Dev

unread,
Sep 8, 2016, 9:41:27 AM9/8/16
to Google Cloud SQL discuss
Hello!

I'm currently developing a Node.js application (Express framework and TypeORM) with MySQL Second Generation. 

When the Node.js application runs on a local machine, they are any problem to connect and use the the MySQL instance. 

But when the Node.js application is deployed on the App Engine, I have this following error "Error: connect ETIMEDOUT" after each query.

Thanks for you help!

----

Dockerfile:
# Use the base App Engine Docker image, based on debian jessie.
FROM gcr
.io/google_appengine/nodejs
# Install specific node.js version
RUN install_node v6
.5.0
# Copy application code.
COPY
. /app/
WORKDIR
/app
# Set common env vars
ENV NODE_ENV dev
 
# Install dependencies.
RUN npm
--unsafe-perm install
# start
CMD
["npm", "start"]

app.yaml:
# [START app_yaml]
#runtime: nodejs
runtime
: custom
vm
: true
beta_settings
:
      cloud_sql_instances
: "<cloud-sql-instance-name>"
# [END app_yaml]

Lekooa Dev

unread,
Sep 8, 2016, 12:45:22 PM9/8/16
to Google Cloud SQL discuss
In fact, the original error comes from the first connection creation after the Node.js application starts: 

{ Error: Connection lost: The server closed the connection.
2016-09-08 15:32:39 default[20160908t164127]      at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:109:13)
2016-09-08 15:32:39 default[20160908t164127]      at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:115:28)
2016-09-08 15:32:39 default[20160908t164127]      at emitNone (events.js:91:20)
2016-09-08 15:32:39 default[20160908t164127]      at Socket.emit (events.js:185:7)
2016-09-08 15:32:39 default[20160908t164127]      at endReadableNT (_stream_readable.js:974:12)
2016-09-08 15:32:39 default[20160908t164127]      at _combinedTickCallback (internal/process/next_tick.js:74:11)
2016-09-08 15:32:39 default[20160908t164127]      at process._tickCallback (internal/process/next_tick.js:98:9)
2016-09-08 15:32:39 default[20160908t164127]      --------------------
2016-09-08 15:32:39 default[20160908t164127]      at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:141:48)
2016-09-08 15:32:39 default[20160908t164127]      at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:52:41)
2016-09-08 15:32:39 default[20160908t164127]      at PoolConnection.connect (/app/node_modules/mysql/lib/Connection.js:136:18)
2016-09-08 15:32:39 default[20160908t164127]      at Pool.getConnection (/app/node_modules/mysql/lib/Pool.js:48:16)
2016-09-08 15:32:39 default[20160908t164127]      at Promise (/app/node_modules/typeorm/driver/mysql/MysqlDriver.js:205:27)
2016-09-08 15:32:39 default[20160908t164127]      at MysqlDriver.retrieveDatabaseConnection (/app/node_modules/typeorm/driver/mysql/MysqlDriver.js:204:20)
2016-09-08 15:32:39 default[20160908t164127]      at MysqlDriver.<anonymous> (/app/node_modules/typeorm/driver/mysql/MysqlDriver.js:101:51)
2016-09-08 15:32:39 default[20160908t164127]      at next (native)
2016-09-08 15:32:39 default[20160908t164127]      at /app/node_modules/typeorm/driver/mysql/MysqlDriver.js:7:65
2016-09-08 15:32:39 default[20160908t164127]      at __awaiter (/app/node_modules/typeorm/driver/mysql/MysqlDriver.js:3:12) fatal: true, code: 'PROTOCOL_CONNECTION_LOST' }



I also forgot to indicate that the different MySQL connection options:
  • locally (working)
    • host: <MySQL_instante_remote_IP_address>
    • port: 3306
    • username: root
    • password: <root_password>
    • database: <database_name>
  • on App Engine (not working)
    • host: localhost
    • port : 3306
    • username: root
    • password: <root_password>
    • database: <database_name>
    • socketPath: “/cloudsql/{projectName}:{zone}:{instance-name}”

On Thursday, September 8, 2016 at 3:41:27 PM UTC+2, Lekooa Dev wrote:
Hello!

I'm currently developing a Node.js application (Express framework and TypeORM) with MySQL Second Generation. 

When the Node.js application runs on a local machine, they are any problem to connect and use the MySQL instance. 

Jason Woan

unread,
May 5, 2017, 12:24:28 PM5/5/17
to Google Cloud SQL discuss
Hi, did you resolve this issue?

I am experiencing a similar situation where I can locally connect the NodeJS app to Google SQL (via the cloud proxy) but deploying to GAE throws a connection error.

It appears that the connection is closed during the handshake process:

<-- HandshakeInitializationPacket
HandshakeInitializationPacket {
  protocolVersion: 10,
  serverVersion: '5.7.14-google-log',
  threadId: 5596,
  scrambleBuff1: <Buffer 14 4a 4e 33 14 49 2c 0e>,
  filler1: <Buffer 00>,
  serverCapabilities1: 63487,
  serverLanguage: 33,
  serverStatus: 2,
  serverCapabilities2: 49663,
  scrambleLength: 21,
  filler2: <Buffer 00 00 00 00 00 00 00 00 00 00>,
  scrambleBuff2: <Buffer 6b 5a 26 35 34 65 23 01 6c 51 7b 36>,
  filler3: <Buffer 00>,
  pluginData: 'mysql_native_password',
  protocol41: true }

--> ClientAuthenticationPacket
ClientAuthenticationPacket {
  clientFlags: 455631,
  maxPacketSize: 0,
  charsetNumber: 33,
  filler: undefined,
  user: *****,
  scrambleBuff: <Buffer f3 9e 6e dc 09 0b 2e 2a b0 70 d9 9a c1 b2 39 53 31 ac c8 2b>,
  database: *****,
  protocol41: true }

Connection fails: Error: Connection lost: The server closed the connection.
It will be retried for the next request.
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Connection lost: The server closed the connection.
    at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:109:13)
    at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:109:28)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickDomainCallback (internal/process/next_tick.js:122:9)

Jun (Cloud Platform Support)

unread,
May 5, 2017, 6:02:43 PM5/5/17
to Google Cloud SQL discuss
Hi Lekooa,

You can find the same exact issue Using Cloud SQL with Node.js => "Error: connect ETIMEOUT" on App Engine filed at GitHub, which seems to be caused by the firewall settings as mentioned in the issue. I would suggest that you should need to use the Cloud SQL Proxy for the Cloud SQL 2nd Gen instance to solve the issue. 

- Jun

Jun (Cloud Platform Support)

unread,
May 5, 2017, 6:12:22 PM5/5/17
to Google Cloud SQL discuss
Hi Jason,

Given your current situation, I suggest that you'll need to open an issue at the Issue Tracker per instructions at Bug reports and provide more information such as your project-ID, Cloud SQL instance name, and other details such as config files for better assistance to your specific issue.

- Jun
Reply all
Reply to author
Forward
0 new messages