Search code examples
c#neo4jhttpclientneo4jclient

Increase HttpClient timeout for Neo4JClient in C#


So I am running a fairly large query which works fine via the shell, but times out when using Readify's GraphClient throwing a "TaskCancelledException".

This behavior is expected since the query takes about 4 minutes to complete when using the shell and the neo4jclient uses a default timeout of 100 seconds.

My Question is: How do I increase this Timeout?

I've found this post which suggests using the IHttpClient to increase the timeout but the post is years old and I do not know how to implement the suggestion. http://hg.readify.net/neo4jclient/issue/70/taskcancelledexception

(PS: The query being ran is :

"match p = shortestPath ((a:Domain{id:"Someid"}))-[:IP]-(b:Domain)) return nodes(p)"

in a graph of a few hundred thousand nodes.

This is not a question about optimizing my query to run faster(Although I'm open to suggestions, but putting an upper bound on the depth will not help lol), it is a necessity that I increase this timeout value!

Thank you


Solution

  • Obviously this is very late, but Neo4jClient was updated to allow you to do this, you can extend the timeout like this:

    var client = new HttpClient { Timeout = TimeSpan.FromMinutes(5) };
    GraphClient gc = new GraphClient(new Uri("http://localhost:7474/db/data"), new HttpClientWrapper("user", "pass", client));
    

    If so inclined, you can whack it all into one line :)