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

When client becomes the "leader" no operations execute against the database #11

Closed
doowb opened this issue Jul 24, 2015 · 1 comment
Closed

Comments

@doowb
Copy link

doowb commented Jul 24, 2015

I'm not sure where to start debugging this except by creating a long running process that does this:

    1. connect to database
    1. get item
    1. write item to console
    1. sleep
    1. goto 2

When running the process along, it will read one item then quit after it sleeps (when it attempts to read an item again)

If I add a second setTimeout and just loops and does nothing to keep the process alone, it's the only one that does anything (after the first read).

When I start 2 processes with the same script, the second one to start will read the item in the loop as expected. If I kill the first process (the "leader"), the second process becomes the "leader" and stops reading from the database.

I'm not sure if this is because the "leader" is a client and server and there's an error that's not propagating or if there's some other cause to this.

Update

I did some more tests and it seems to only happen when using accountdown and using the .list() method (which returns a stream).

Here's the script that I was using. I have the timeouts set high in this case so I can switch to another console and start it again. After the "leader" dies, and another "leader" is elected, it stops reading, then dies.

var mkdirp = require('mkdirp');
var level = require('level-party');
var sublevel = require('level-sublevel');
var accountdown = require('accountdown');

mkdirp.sync('./tmp/data');
var db = level('./tmp/data')
db.on('leader', console.log.bind(console, "I'm the leader"));
// db = sublevel(db);
var accounts = accountdown(db, {
  login: { basic: require('accountdown-basic') }
});

var start = new Date();

function writeMsg () {
  var opts = {
    login: {basic: {username: 'doowb', password: 'password'}},
    value: {name: 'Brian Woodward'}
  };
  accounts.create('doowb', opts, function (err) {
    setTimeout(writeMsg, 10000);
  });
  // var diff = (new Date()) - start;
  // db.put('time', diff.toString(), function (err) {
  //   if (err) console.error('Error writing diff', err);
  //   setTimeout(writeMsg, 1000);
  // });
}

function readMsg () {
  accounts.list()
    .on('data', console.log)
    .on('end', function () {
      setTimeout(readMsg, 2000);
    });
  // db.get('time', function (err, diff) {
  //   if (err && err.notFound) console.error('Message not found', err);
  //   if (err && !err.notFound) console.error('Error', err);
  //   console.log('Diff:', diff);
  //   setTimeout(readMsg, 200);
  // });
}

writeMsg();
setTimeout(readMsg, 5000);
@vweevers
Copy link
Member

vweevers commented Dec 8, 2019

I did some more tests and it seems to only happen when using accountdown

Merging into #12.

@vweevers vweevers closed this as completed Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants