Skip to content
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

Error: A slave with the same server_uuid/server_id as this slave has connected to the master; #21

Open
MInesGomes opened this issue Aug 29, 2019 · 11 comments
Labels
help wanted Extra attention is needed

Comments

@MInesGomes
Copy link

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?

@rodrigogs
Copy link
Owner

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?

@rodrigogs rodrigogs added the help wanted Extra attention is needed label Aug 29, 2019
@MInesGomes
Copy link
Author

MInesGomes commented Aug 29, 2019 via email

@dalborgo
Copy link

dalborgo commented Apr 3, 2020

Same problem for me.

@MInesGomes
Copy link
Author

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

@dalborgo
Copy link

dalborgo commented Apr 8, 2020

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.

@rodrigogs
Copy link
Owner

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.

@rmccownISoft
Copy link

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.

@dalborgo
Copy link

dalborgo commented Apr 23, 2020

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'))

@rmccownISoft
Copy link

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.'

@ubuntutest
Copy link

ubuntutest commented May 25, 2020

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?

@imzers
Copy link

imzers commented Nov 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants