Random ECONNRESET when talking to docker mysql
See original GitHub issueHi all,
I have a big issue where I randomly get ECONNRESET every 1-5 minutes when using mysql / mysql2 npm package. ( Works fine up until this point )
Environment
mysql server
running in docker, mapped to host port 3306node server
running within docker, talking to mysql via host_ip:3306
Errot
data-server-container | Error: read ECONNRESET
data-server-container |
data-server-container | - net.js:622 TCP.onread
data-server-container | net.js:622:25
Fix attempts
I’ve tried all sorts to try and get the connection to remain - including
Using pools
const mysql = require('mysql2');
const connection = await mysql.createPool({
connectionLimit: 10,
host: process.env.DB_HOST_DOCKER,
user: process.env.DB_USER_DOCKER,
password: process.env.DB_PASSWORD_DOCKER,
database: process.env.DB_DATABASE,
});
query = (sql) => {
return new Promise(async (resolve, reject) => {
connection.getConnection(function (err, poolConnection) {
if (err) throw err; // not connected!
// Use the connection
poolConnection.query(sql, function (error, results, fields) {
if (error) reject(error)
resolve(results);
// When done with the connection, release it.
poolConnection.release();
})
})
})
}
Creating a new connection on every request! ( Somehow this still gets ECONNRESET! )
query = (sql) => {
const mysql = require('mysql2');
const connection = await mysql.createConnection({
host: process.env.DB_HOST_DOCKER,
user: process.env.DB_USER_DOCKER,
password: process.env.DB_PASSWORD_DOCKER,
database: process.env.DB_DATABASE,
});
return new Promise(async (resolve, reject) => {
connection.query(sql, (error, results) => {
if (error) {
reject(error);
}
resolve(results);
});
}
}
- Sending a ping to the connection every 10 seconds
- Checking my wait_timeout is high enough on mysql server ( 28800 as expected )
I’m running out of ideas here it’s stopping me being able to use this in production 😦
My best assumption after trying all the above is there an issue with the TCP Keep-Alive on the socket perhaps that is only triggered when running node / mysql within docker ( I stumbled on this MR - could this be a solution? https://github.com/mysqljs/mysql/pull/2110/ )
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Random ECONNRESET when talking to docker mysql #2149
Hi all, I have a big issue where I randomly get ECONNRESET every 1-5 minutes when using mysql / mysql2 npm package.
Read more >How do I debug error ECONNRESET in Node.js?
"ECONNRESET" means the other side of the TCP conversation abruptly closed its end of the connection. This is most probably due to one...
Read more >Fix a random network Connection Reset issue in Docker ...
This article describes my recent experience to fix a random network “Connection Reset” issue in CI/CD pipelines running in Docker/Kubernetes ...
Read more >nodejs mysql docker ECONNRESET if idle for 16 minutes ...
If it still doesn't work, try to diagnose. In checkConnection() delete the SQL query to make the script not crash and wait 16...
Read more >How To Setup And Use MySQL DOCKER Container
This tutorial explains the step-by-step method to set up and use the MySQL Docker container with examples.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem is related to docker swarm and pooling.
Disable pooling (in knex file : pool: {min:0} )
Or check out this: https://success.docker.com/article/ipvs-connection-timeout-issue
I had the same problem until I added
command: "--wait_timeout=28800"
to my docker-compose file. I’m running MariaDB though, but it might be the same problem.Example docker-compose:
Here’s a link to the MariaDB documentation:
https://mariadb.com/kb/en/server-system-variables/#wait_timeout