node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

read: connection reset by peer

Open habuildserver opened this issue 1 year ago • 1 comments

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.

  1. Error: unavailable: unexpected EOF\n at PromisePoolConnection.execute
  2. read: connection reset by peer
  3. 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;
    }
};

habuildserver avatar Jan 01 '24 09:01 habuildserver

could you try to log what was the SQL for the Error: unavailable: unexpected EOF\n at PromisePoolConnection.execute error?

sidorares avatar Jan 02 '24 01:01 sidorares