node-mysql2
node-mysql2 copied to clipboard
read: connection reset by peer
We are connecting to planetscale through expressjs using mysql2. We are fetching around 1 million records in pagination manner 50k rows at time and using below code for the same.
We are getting below random errors.
- Error: unavailable: unexpected EOF\n at PromisePoolConnection.execute
- read: connection reset by peer
- unavailable: unexpected EOF, Error: unavailable: unexpected EOF
Source Code
const mysql = require('mysql2');
// Create the connection pool. The pool-specific settings are the defaults
const pool = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DATABASE,
waitForConnections: true,
connectionLimit: 10,
maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`
idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000
queueLimit: 0,
enableKeepAlive: true,
keepAliveInitialDelay: 0,
ssl: {
rejectUnauthorized: true,
},
});
// Export a function to query the database
const queryExecuteHelper = (sql, values) => {
return new Promise((resolve, reject) => {
pool.query(sql, values, (error, results) => {
if (error) {
reject(error);
} else {
resolve(results);
}
});
});
};
const executeQueryNewFn = async (query, params = []) => {
try {
const result = await queryExecuteHelper(query, params);
return { results: result };
} catch (error) {
throw error;
}
};
could you try to log what was the SQL for the Error: unavailable: unexpected EOF\n at PromisePoolConnection.execute error?