mysql-events
mysql-events copied to clipboard
Error: A slave with the same server_uuid/server_id as this slave has connected to the master;
Hi @rodrigogs,
Has been working great! But looking at the log error I saw a new one:
'A slave with the same server_uuid/server_id as this slave has connected to the master; the first event 'mysql-bin.000089' at 43535345, the last event read from '/mysql/binlog/mysql-bin.000089' at 56994447, the last byte read from '/mysql/binlog/mysql-bin.000089' at 56994447.', sqlState: 'HY000' }
I have 2 databases (Production, Development ) And have 2 listeners that gives this error
My Code Dev
const mysql = require('mysql');
var MySQLEvents = require("@rodrigogs/mysql-events");
const schemaName ='nms';
My Code Prod
const mysql = require('mysql');
var MySQLEvents = require("@rodrigogs/mysql-events");
const schemaName ='nmsProd';
Same code for both
const db_config = { host: '35.234.131.94', user:XXX', password: XXX', database: schemaName, };
let connectDB = mysql.createConnection(db_config);
let instance = new MySQLEvents(connectDB, {
startAtEnd: true,
excludedSchemas: {
mysql: true
},
});
startTrigers();
function handleDisconnect() {
console.log('handleDisconnect');
connectDB.destroy();
connectDB = mysql.createConnection(db_config);
connectDB.connect(function (err) {
if (err) {
console.log(' Error when connecting to db (DBERR001):', err);
setTimeout(handleDisconnect, 1000);
}
else{
// startTrigers();
}
});
}
instance.on(MySQLEvents.EVENTS.CONNECTION_ERROR, (err) => {
console.log('Connection is asleep (time to wake it up): ', err);
setTimeout(handleDisconnect, 1000);
handleDisconnect();
});
instance.on(MySQLEvents.EVENTS.ZONGJI_ERROR, console.error);
function startTrigers() {
instance.start();
instance.addTrigger({
name: 'ALERT_INSERTED',
expression: schemaName + '.nms_alert',
statement: MySQLEvents.STATEMENTS.INSERT,
onEvent: (event) => {
console.log("", new Date());
console.log("==== ALERT INSERTED ===");
sendAlert(event);
},
});
Do I have to change something?
This is probably a MySQL error related to the binlog state. I don't think it will stop the app from working properly tho. Do you think you missed any event due to this?
Yes, I think is working ok. I am restarting the app every day … So not sure ...
On 29 Aug 2019, at 19:44, Rodrigo Gomes da Silva [email protected] wrote:
This is probably a MySQL error related to the binlog state. I don't think it will stop the app from working properly tho. Do you think you missed any event due to this?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rodrigogs/mysql-events/issues/21?email_source=notifications&email_token=AAYZAHWMO3X63V6BYOBOGBLQHADI5A5CNFSM4ISBEJI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5PIZ2Y#issuecomment-526290155, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYZAHQZR2XFM7MU4R3O3CLQHADI5ANCNFSM4ISBEJIQ.
Same problem for me.
Yes. I need to start more than every day and found another way to do what I need it. So for the moment not using sqlevents
In my case, the error occurred when I restart the triggers (your "startTrigers" function). For a moment it creates a conflict with the precendet instance (or something of similar...). But the real problem is the disconnection from the server that, in my case, happens every 8 hours (my server is an amazonAWS one). If I force to restart the entire script, when an CONNECTION_ERROR occurred, I don't get the topic error. So I belive it's a instances problem. I recreate a new MySQLEvents instance too.
Sorry for not being able to help. I'm deeply involved in some COVID-19 urgent projects and it's sucking my time to the bone.
Hopefully someone has a solution, otherwise this library is useless after the first time it disconnects. Looks like the control connection gets disconnected after the wait_timeout but the binlog connection remains. Try to pass it a new connection as above returns the "slave with same server_id" error.
You can try to force the instance to stop before restart the connection.
instance.stop()
This is my code and I don't get the topic error anymore.
const stopInstance = async () => {
try {
await instance.stop()
return { ok: true, results: true }
} catch (err) {
return { ok: false, message: err.message, err }
}
}
const manageError = origin => async err => {
console.error(origin, err.message)
try {
console.log('Restarting due connection error!')
const { ok, message } = await stopInstance()
if (ok) {console.log('ZONGJI instance stopped!')} else {console.error(message)}
connErrorCallback()
} catch (err) {
console.error('Restarting error', err.message)
if (cFunctions.isProd()) {
process.exit(1) //force to exit and restart with pm2
}
}
}
instance.on(MySQLEvents.EVENTS.CONNECTION_ERROR, manageError('CONNECTION_ERROR'))
Unfortunately, I've not managed to get instance.stop() to work in any iteration, I always end up with 'UnhandledPromiseRejectionWarning: Error: Cannot enqueue Quit after fatal error.'
please don't flame me, i'm really new with nodejs, i don't know exactly what i'm doing. But to solve this problem I assigned a random value, (more precisely the current date) so I know it will never have the same value.
const instance = new MySQLEvents(connection, {
startAtEnd: true,
serverId: Date.now()
});
is this totally wrong?
Hi, I have this error before, my environment was a master and some slave database, there is replication from slave-db to master-db and if I using mysql-events plugin to connect from another vm, it get error (A slave with the same server_uuid/server_id as this slave has connected....) Found solustion by connect with another user with REPLICATION_SLAVE & REPLICATION_CLIENT privileges and unique server_id from concurrent connection https://dba.stackexchange.com/questions/231414/error-a-slave-with-the-same-server-uuid-server-id-as-this-slave-has-connected