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

Safe lookup #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Safe lookup #4

wants to merge 2 commits into from

Conversation

delvedor
Copy link
Member

In the case there are two nodes and one of them is a client node, if the not-client node goes down, the client node will throw an exception here:

return this._entries[index].peer

Because it's searching the key peer on and undefined object.
I'm having some trouble to test this, any suggestion?

Do we agree on the fix?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test?

return this._entries[index].peer
if (this._entries[index]) {
return this._entries[index].peer
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case index >= this._entries.length? I think it might happen, but a comment would be good.

@delvedor
Copy link
Member Author

@mcollina I would like to do it, but I'm having some issue to reproduce the error outside of a project which I'm working on.
This is what I've done so far, but is not working (the close callback is never called):

test('gracefully shutdown a client if there are no more node in the ring', t => {
  t.plan(1)

  const peer = hashring({
    joinTimeout: 1000
  })

  peer.on('up', () => {
    console.log('peer up')
    const client = hashring({
      joinTimeout: 1000,
      client: true,
      base: [peer.whoami()]
    })

    client.on('up', () => {
      console.log('client up')
      peer.close(() => {
        console.log('peer closed')
      })
    })
  })
})

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

Successfully merging this pull request may close these issues.

2 participants