Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

fix: random walk #104

Merged
merged 9 commits into from
Apr 22, 2019
Merged

fix: random walk #104

merged 9 commits into from
Apr 22, 2019

Conversation

jacobheun
Copy link
Contributor

Random Walk had some bugs, this fixes them:

  • If you ever specified more than 1 query, it would never run them. (You really shouldn;t need more than 1, but still not a good bug)
  • We timed out the walk, but findPeer wasn't given the walks timeout. So if you specified 10seconds as your walk timeout, the findPeer logic would keep running until its default timeout kicked in (60 seconds)

I added a suite of tests just for RandomWalk to test the failures I was seeing.

This also adds support for AbortController in random walk and passes it to findPeer, however, findPeer currently isn't listening to the abort signal so it won't actually stop the query. My thought is to wait until we finish #82 and then add the abort logic to all of the query methods. Once we do, random walk will immediately benefit because it already passes the signal in. @dirkmc @vasco-santos let me know what you think, and I can update accordingly.

findPeer needs to be updated to support an abort controller
@ghost ghost assigned jacobheun Apr 18, 2019
@ghost ghost added the status/in-progress In progress label Apr 18, 2019
Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

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

It's great to have this really comprehensive testing for random walk 👍

I'm not sure I'd include the AbortController logic until we move to an async/await API

src/index.js Outdated Show resolved Hide resolved
src/random-walk.js Outdated Show resolved Hide resolved
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

I am not against adding the AbortController logic in this PR. But we should have a comment explaining it will not be used for now / WIP

src/random-walk.js Outdated Show resolved Hide resolved
src/random-walk.js Show resolved Hide resolved
@jacobheun
Copy link
Contributor Author

I've removed the runningHandler logic and simplified the code. I also bumped up the default timeout to 30s from 10s. Since we are passing on the timeout to findPeer, and it actually times the query out, giving it more time to run will improve the effectiveness.

I also disabled random walk in the TestDHT util by default to keep the tests isolated better. We're managing connects as needed in the tests, having random walk running will just cause more test chaos.

I added a comment to the RandomWalk._query function about the AbortController not yet being properly supported and removed the docs for options.signal from findPeer.

@jacobheun jacobheun marked this pull request as ready for review April 18, 2019 15:51
@@ -73,7 +73,7 @@ function connect (a, b, callback) {

function bootstrap (dhts) {
dhts.forEach((dht) => {
dht.randomWalk._walk(1, 1000, () => {})
dht.randomWalk._walk(1, 10000, () => {})
Copy link
Contributor Author

@jacobheun jacobheun Apr 18, 2019

Choose a reason for hiding this comment

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

Now that timeout is actually being passed to findPeer I bumped this to 10seconds so the random walk doesn't get killed after 1s. This was causing test failures because routing tables weren't doing enough connecting when it was depending on the walk.

@jacobheun jacobheun requested review from dirkmc and vasco-santos and removed request for dirkmc April 18, 2019 15:53
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

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

One comment but otherwise LGTM 👍

Thanks for cleaning up how the tests work as well!

src/random-walk.js Outdated Show resolved Hide resolved
@vasco-santos vasco-santos merged commit 9db17eb into master Apr 22, 2019
@ghost ghost removed the status/in-progress In progress label Apr 22, 2019
@vasco-santos vasco-santos deleted the fix/random-walk branch April 22, 2019 09:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants