Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Randomized picking of peer to request space from is not random #1004

Closed
bboreham opened this issue Jun 24, 2015 · 3 comments · Fixed by #1068
Closed

Randomized picking of peer to request space from is not random #1004

bboreham opened this issue Jun 24, 2015 · 3 comments · Fixed by #1068
Assignees
Milestone

Comments

@bboreham
Copy link
Contributor

Neither weave's picking of a random number nor Go's picking of a random order to iterate the hashtable is seeded, so they always pick the same ones, for a given set of start conditions.

@rade
Copy link
Member

rade commented Jun 25, 2015

What is the user-visible manifestation of this?

@bboreham
Copy link
Contributor Author

Supposing the particular node picked does not respond, and no error gets back to the caller; e.g. messages are dropped by an intermediate peer, then the user may restart weave and try again, then weave will pick exactly the same peer, so if the same conditions result in no response then this will be user-visible.

Post- #1010, this is a much more unlikely scenario.

@rade
Copy link
Member

rade commented Jul 3, 2015

So we could either initialise our own random source, or seed the global source with rand.Seed( time.Now().UTC().UnixNano()). I am tempted to do the latter, especially since NewSource does not return thread-safe sources, so we'd have to re-invent the locking that golang has kindly hidden for us in the unexported lockedSource which is used by the global source.

The question is where to put that seeding call. It seems dodgy to place it in an init() in a library, since then multiple initialisations can occur (which is ok, I guess, except when they occur in the same nanosecond). I see that your friends at Hashicorp don't seem to be bothered by this - serf includes memberlist and both have an init() that seeds the global random source.

@rade rade added this to the current milestone Jul 3, 2015
@rade rade closed this as completed in #1068 Jul 3, 2015
rade added a commit that referenced this issue Jul 3, 2015
Seed random-number generator from the host time

Fixes #1004.
@rade rade modified the milestones: current, 1.1.0 Jul 13, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants