Skip to content

MySQL server disconnects after a few hours despite using pools #993

@gregcarlin

Description

@gregcarlin

We are using pool.query to query a MySQL database, but after running our website for a few hours we get an error:

Error: Connection lost: The server closed the connection. 
at Protocol.end (/opt/node-v0.10.20-linux-x64/IM/node_modules/mysql/lib/protocol/Protocol.js:73:13)
at Socket.onend (stream.js:79:10)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)

And our server can no longer connect to the MySQL database. We are using pools, so I thought the pool would automatically reconnect to the DB. Here's the code we use to create the pool:

pool = mysql.createPool({
  connectionLimit    : 10,
  host               : creds.mysql_host,
  port               : creds.mysql_port,
  database           : creds.mysql_db,
  user               : creds.mysql_user,
  password           : creds.mysql_pass,
  multipleStatements : true
});

And when we query the pool we do

pool.query("statement", [inputs], callback);

I have found similar issues online when people are using pool.getConnection without calling connection.release(), but we are using pool.query and cannot release the connection manually.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions