Skip to content

Randomize feature of StaticConnectionPool does nothing #4055

@kit299

Description

@kit299

NEST/Elasticsearch.Net version: 6.0.2 and 7.2.1 (presumably others)

Elasticsearch version: irrelevant, but 6.6.1

Description of the problem including expected versus actual behavior:

See: https://github.com/elastic/elasticsearch-net/blob/master/src/Elasticsearch.Net/ConnectionPool/StaticConnectionPool.cs
(current latest revision is c330114)

In theory passing 'true' for the randomize parameter (true is also the default for this parameter) will cause the order of the supplied nodes to be randomized.
This should happen in the function SortNodes() which (if no node scorer is available) will check the Randomize property and, if true, will use OrderBy(Random.Next()) to return the nodes in a random order.

In practice, because of the way the constructors are nested, SortNodes is called from the protected constructor BEFORE the Randomize property is initialized by the public constructor - so when read in SortNodes the Randomize property has not yet been initialized and will always have its default value of false.

Steps to reproduce:

var uris = new[]
{
	new Uri("https://10.0.0.1:9200/"),
	new Uri("https://10.0.0.2:9200/"),
	new Uri("https://10.0.0.3:9200/")
};

var pool = new StaticConnectionPool(uris);
var nodeView = pool.CreateView();

Debug.Assert(nodeView.First().Uri.ToString() == "https://10.0.0.1:9200/");

Expected: The assertion should fail most of the time.
Actual: The assertion never fails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions