Error: This socket has been ended by the other party
See original GitHub issueHello,
First of all, thanks @sidorares for all the good work you’ve been putting in this package! I’ve looked around at other issues but can’t seem to find a valid answer for this issue.
My app queries every morning a DB and I get this error 50% of mornings as I guess the connection timedout but my mysql2 connection pool normally closes each connection after it uses it so don’t know why it tries to query on a timedout connection.
Stack trace:
Error: This socket has been ended by the other party
at TLSSocket.writeAfterFIN [as write] (net.js:402:12)
at PoolConnection.connection.write (/opt/test_api_sandbox/node_modules/mysql2/lib/connection.js:387:20)
at PoolConnection.Connection.writePacket (/opt/test_api_sandbox/node_modules/mysql2/lib/connection.js:304:10)
at Query.start (/opt/test_api_sandbox/node_modules/mysql2/lib/commands/query.js:48:14)
at Query.Command.execute (/opt/test_api_sandbox/node_modules/mysql2/lib/commands/command.js:40:20)
at PoolConnection.Connection.handlePacket (/opt/test_api_sandbox/node_modules/mysql2/lib/connection.js:513:28
at PoolConnection.Connection.addCommand (/opt/test_api_sandbox/node_modules/mysql2/lib/connection.js:534:10)
at PoolConnection.query (/opt/test_api_sandbox/node_modules/mysql2/lib/connection.js:623:15)
at /opt/test_api_sandbox/node_modules/mysql2/lib/pool.js:166:10
at /opt/test_api_sandbox/node_modules/mysql2/lib/pool.js:42:14
(node:9571) UnhandledPromiseRejectionWarning: Error: This socket has been ended by the other party
at TLSSocket.writeAfterFIN [as write] (net.js:402:12)
at PoolConnection.connection.write (/opt/test_api_sandbox/node_modules/mysql2/lib/connection.js:387:20)
at PoolConnection.Connection.writePacket (/opt/test_api_sandbox/node_modules/mysql2/lib/connection.js:304:10)
at Query.start (/opt/test_api_sandbox/node_modules/mysql2/lib/commands/query.js:48:14)
at Query.Command.execute (/opt/test_api_sandbox/node_modules/mysql2/lib/commands/command.js:40:20)
at PoolConnection.Connection.handlePacket (/opt/test_api_sandbox/node_modules/mysql2/lib/connection.js:513:28
at PoolConnection.Connection.addCommand (/opt/test_api_sandbox/node_modules/mysql2/lib/connection.js:534:10)
at PoolConnection.query (/opt/test_api_sandbox/node_modules/mysql2/lib/connection.js:623:15)
at /opt/test_api_sandbox/node_modules/mysql2/lib/pool.js:166:10
at /opt/test_api_sandbox/node_modules/mysql2/lib/pool.js:42:14
my database handler file:
const mysql = require('mysql2/promise');
const fs = require('fs');
require('dotenv').load();
const pool = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
ssl: {
ca: fs.readFileSync(process.env.DB_SSL_CA),
key: fs.readFileSync(process.env.DB_SSL_KEY),
cert: fs.readFileSync(process.env.DB_SSL_CERT)
},
multipleStatements: true
});
module.exports.query = function (query, value) {
let connection;
return pool.getConnection().then(conn => {
connection = conn;
return connection.query(query, value);
})
.then(res => res[0])
.catch(err => err)
.then(res => {
connection.release();
return res;
});
};
I use mysql2 ^1.6.1
As you see, at the end of each query I release the connection so this means there should be any idle connection which can timeout right?
Thanks Anjan
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
What causes Error: This socket has been ended by the other ...
Typically this is sent when another application (client, browser, etc.) closes the socket when you are still sending data to it from the...
Read more >Nodejs Error: This socket has been ended by the other party
My understanding of sockets is that they represent endpoints in a stream between the client and the server. When that stream is no...
Read more >SideQuest Community Support | SideQuest
ncaught Exception: Error: This socket has been ended by the other party at Socket.writeAfterFIN [as write] (net.js:456:14) at Connection.write ...
Read more >Help plz : r/sidequest - Reddit
A JavaScript error occurred in the main process. Uncaught Exception: Error: This socket has been ended by the other party. at Socket.
Read more >Occasional "Unhandled 'error' event" exception no matter what ...
... 2048MB memory limit events.js:292 throw er; // Unhandled 'error' event ^ Error: This socket has been ended by the other party at...
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
@bonbonio @anjansom just published v1.6.2, let me know if that fixes your issue
I’m using
"mysql2": "^1.6.4"
on Google App Engine, and I’m still receiving this issue.I had assumed it was occurring when mysqld’s
wait_timeout
of 60 (seconds) closes an idle pool connection, but this is definitely not the case, as the connection pool happily notes the connection as dead and opens a fresh one without issue. Ditto if, on the server, Ikill nnnnn
the connection myself.Not too sure what might be causing this.