-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Error: This socket has been ended by the other party. #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi! Can you at least post the stack trace that goes with the error? That will allow us to help you much better. |
Well I've put on debugging, and I'm waiting for it to happen again. How would I enable a stack trace? |
When you get the error object, the stack trace is located in the stack property: |
Okay finally managed to get a stack. Even with debug on, no query or anything is displayed so all I have to show for is this:
|
Great, thanks! So here is what is happening: the library is accidentally trying to write over the TCP socket after a Are you using the connection pool? It looks like you are just making a query on a connection after some timeout according to the stack trace. It's possible you are holding onto an inactive connection too long and something on the network or MySQL server is ending the connection. |
This seems strange though. I use this code which should reconnect automatically:
Then later on I proceed with something like this:
At times the connection is timed out, it will reconnect, or at least I believe so. Could it be closing the connection and not throwing an error? |
Oh, OK. It is because it's a simple JavaScript mistake. You are reconnecting, but you cannot actually change the // Generated by LiveScript 1.2.0
// Edited: replaced all "db" with "exports.db"
(function(){
var mysql, config, handleDisconnect, this$ = this;
mysql = require('mysql');
config = require('./config');
exports.db = null;
handleDisconnect = function(){
exports.db = mysql.createConnection(config.db);
exports.db.connect(function(err){
if (err != null) {
console.log('Error connecting to mysql:', err);
exports.db = null;
return setTimeout(handleDisconnect, 2000);
}
});
return exports.db.on('error', function(err){
console.log('Database error:', err);
if (err.code === 'PROTOCOL_CONNECTION_LOST') {
exports.db = null;
return handleDisconnect();
} else {
return process.exit(1);
}
});
};
handleDisconnect();
}).call(this); then in your other place: Connection = require('../connection');
// Edited: replaced all "Connection" with "Connection.db"
if (Connection.db == null) {
this.send('We cannot reach the database right now, please try again later.');
return;
}
// Variables are set else where but used below.
Connection.db.query("UPDATE users SET experience = experience + ? WHERE username = ?", [experience, username], function(error){
if (error != null) {
console.log('Query error: ' + error);
console.log(error.stack);
process.exit(1);
}
this$.send(username + " earned " + experience + "XP");
pointer++;
}); i.e. you need to reference an object lookup, not the variable directly. This is a common JavaScript mistake because people confuse global variables that are an implicit object lookup vs. lexical variables that are a direct reference. When you reconnect in your reconnect code, you are not actually changing what |
What exactly is the error in question?
Error: This socket has been ended by the other party
This happens at random times, not quite sure what's triggering it. I received it twice, one after a long period of inactivity and one after a rather short period but doesn't always happen. I now have debug on and waiting for it to happen again but this could take all day, oh the joy.
I've set the timeout on the server to 60 seconds though, just to speed up debugging and well I must say the connection doesn't timeout after 60 seconds so I'm not sure what that is all about, at least with node as it would spit out an error when it is timeouted and then reconnect which doesn't happen. Hopefully I can find more information with debugging on, but until then what exactly is that error and how can I prevent it?
The text was updated successfully, but these errors were encountered: