Skip to content

Custom domain resolver ignores port #838

@stefano-ottolenghi

Description

@stefano-ottolenghi

The following code errors with

nhandled exception. Neo4j.Driver.ServiceUnavailableException: Unable to connect to database, ensure the database is running and that there is a working network connection to it.
---> Neo4j.Driver.ServiceUnavailableException: Failed to find server info for 'neo4j://localhost:7687/' for database 'system'.

using Neo4j.Driver;

string dbUri = "localhost";
string dbUser = "neo4j";
string dbPassword = "verysecret";

var addresses = ServerAddress.From(dbUri, 7687);

using var driver = GraphDatabase.Driver(
    "neo4j://example.com:9999",
    AuthTokens.Basic(dbUser, dbPassword),
    conf => conf.WithResolver(new ListAddressResolver(addresses))
);
await driver.VerifyConnectivityAsync();

class ListAddressResolver : IServerAddressResolver {
    private readonly ServerAddress[] _servers;

    public ListAddressResolver(params ServerAddress[] servers) {
        _servers = servers;
    }

    public ISet<ServerAddress> Resolve(ServerAddress address) {
        return new HashSet<ServerAddress>(_servers);
    }
}

The issue is two-fold:

  1. the driver claims the server is not available at localhost:7687, while there is one up and running. Grant's assessment is that the port is ignored. This is thus a bug because the error message claims to be connecting to port 7687 while (apparently?) it's actually reaching to 9999.
  2. it would make for a hugely improved UX if we provided a default implementation of ListAddressResolver so users don't have to copy-paste the boilerplate. In the end there's rarely anything special happening there: most often it's just a list of addresses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions