node-mysql2
node-mysql2 copied to clipboard
Error: This socket has been ended by the other party
My database is in a VPN, so I need to connect to database through a tunnel. I try but receive this error:
Error: This socket has been ended by the other party
at Socket.writeAfterFIN [as write] (net.js:455:14)
at Channel.ondata (_stream_readable.js:716:22)
at Channel.emit (events.js:315:20)
at Channel.Readable.read (_stream_readable.js:505:10)
at flow (_stream_readable.js:1005:34)
at resume_ (_stream_readable.js:986:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EPIPE'
}
At which stage do you see this error? ( at connection before even getting a query or sporadically during the life of connection )
Hi @sidorares,
After entering the tunnel, I try to connect to the MySQL server. Here is my code:
const mysql = require("mysql2/promise");
module.exports.checkMysqlConnection = async function (credentials) {
const connection = await mysql.createConnection(credentials);
await connection.end();
};
So I think that I get this error at the create connection stage. I just wanna test the connection whether it succeeded or not. I ran this code inside a thread to make sure there is no port conflicting since I mapped to a random port.
Still getting this error in staging/production today, latest version:
Error: This socket has been ended by the other party
at Socket.writeAfterFIN [as write] (net.js:456:14)
at Connection.write (/data/node_modules/mysql2/lib/connection.js:230:32)
at Connection.writePacket (/data/node_modules/mysql2/lib/connection.js:279:12)
at Quit.start (/data/node_modules/mysql2/lib/commands/quit.js:24:16)
at Quit.execute (/data/node_modules/mysql2/lib/commands/command.js:39:22)
at Connection.handlePacket (/data/node_modules/mysql2/lib/connection.js:425:32)
at Connection.addCommand (/data/node_modules/mysql2/lib/connection.js:447:12)
at Connection.end (/data/node_modules/mysql2/lib/connection.js:819:26)
at /data/node_modules/mysql2/promise.js:128:23
at new Promise (<anonymous>)
Emitted 'error' event on Connection instance at:
at Connection._notifyError (/data/node_modules/mysql2/lib/connection.js:225:12)
at Connection._handleFatalError (/data/node_modules/mysql2/lib/connection.js:156:10)
at Connection._handleNetworkError (/data/node_modules/mysql2/lib/connection.js:169:10)
at Socket.emit (events.js:376:20)
at Socket.emit (domain.js:470:12)
at emitErrorNT (net.js:1345:8)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
code: 'EPIPE',
fatal: true
}
Why not check for the connection being closed here? Obviously the error callback is ineffective in handling these low-level socket errors.
Still getting these errors on occasional, out of the blue:
events.js:377
throw er; // Unhandled 'error' event
^
Error: This socket has been ended by the other party
at Socket.writeAfterFIN [as write] (net.js:468:14)
at Connection.write (/data/node_modules/mysql2/lib/connection.js:230:32)
at Connection.writePacket (/data/node_modules/mysql2/lib/connection.js:279:12)
at Quit.start (/data/node_modules/mysql2/lib/commands/quit.js:24:16)
at Quit.execute (/data/node_modules/mysql2/lib/commands/command.js:39:22)
at Connection.handlePacket (/data/node_modules/mysql2/lib/connection.js:425:32)
at Connection.addCommand (/data/node_modules/mysql2/lib/connection.js:447:12)
at Connection.end (/data/node_modules/mysql2/lib/connection.js:819:26)
at /data/node_modules/mysql2/promise.js:128:23
at new Promise (<anonymous>)
Emitted 'error' event on Connection instance at:
at Connection._notifyError (/data/node_modules/mysql2/lib/connection.js:225:12)
at Connection._handleFatalError (/data/node_modules/mysql2/lib/connection.js:156:10)
at Connection._handleNetworkError (/data/node_modules/mysql2/lib/connection.js:169:10)
at Socket.emit (events.js:400:28)
at emitErrorNT (net.js:1358:8)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
code: 'EPIPE',
fatal: true
}
Is there no way to prevent these from being fatal? I'm fine with a connection/query throwing such an error, as I can catch it, but this takes out the whole service.