4

I am making a pretty long query to Neo4j database using Neo4jClient and getting an exception which occurs pretty randomly. How to fix this?

System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.



--- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Neo4jClient.GraphClient.<>c__DisplayClass3.<SendHttpRequestAsync>b__2(Task`1 requestTask) in c:\TeamCity\buildAgent\work\f1c4cf3efbf1b05e\Neo4jClient\GraphClient.cs:line 149
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Neo4jClient.GraphClient.<>c__DisplayClass1b`1.<Neo4jClient.IRawGraphClient.ExecuteGetCypherResultsAsync>b__1a(Task`1 responseTask) in c:\TeamCity\buildAgent\work\f1c4cf3efbf1b05e\Neo4jClient\GraphClient.cs:line 745
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
---> (Inner Exception #0) System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Neo4jClient.GraphClient.<>c__DisplayClass3.<SendHttpRequestAsync>b__2(Task`1 requestTask) in c:\TeamCity\buildAgent\work\f1c4cf3efbf1b05e\Neo4jClient\GraphClient.cs:line 149
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
---> (Inner Exception #0) System.Threading.Tasks.TaskCanceledException: A task was canceled.<---
<---
Martynas
  • 1,064
  • 10
  • 21
  • Can you share some more information on the type of query and the complexity of your graph? It seems that Neo4jClient may be timing out due to the query taking too long to complete. – Cameron Tinker Apr 01 '13 at 18:15
  • It is pretty complex and it takes a couple of minutes to complete. Yes, it is possible that the client is timing out. However, the time after which the error occurs is not consistent. – Martynas Apr 02 '13 at 19:41

2 Answers2

3

This is being tracked as an issue at https://bitbucket.org/Readify/neo4jclient/issue/70/taskcancelledexception

Diagnosis and eventual 'official' resolution will be posted there.

Tatham Oddie
  • 4,290
  • 19
  • 31
0

It took me hours to identify this issue and fix it.

[edit]: Don't use Neo4jClient.GraphClient, use Neo4jClient.BoltGraphClient - both derive from IGraphClient - the BoltGraphClient doesn't use an HttpClient behind the scenes and is way faster and less memory intensive.

var BoltGraphClient = new Neo4jClient.BoltGraphClient(url,username,password);

my old answer + story:

I'm putting a ton of Cypher queries into a List<Task> and executing them via query.ExecuteWithoutResultsAsync(). The Neo4j server can only handle so much at a time and will put the request in a queue.

I've confirmed that the TaskCanceledException gets thrown after 100 seconds, which is the default timeout of HttpClient.

After reading the documentation, I've figured out how to specify an infinite timespan during the initialization of the graphclient. Hope this will save you time.

var httpClientWrapper = new Neo4jClient.HttpClientWrapper(
        username,
        password,
        new System.Net.Http.HttpClient() {
             Timeout = System.Threading.Timeout.InfiniteTimeSpan
        });

var graphClient = new Neo4jClient.GraphClient(new Uri(url), httpClientWrapper);
Ambrose Leung
  • 3,704
  • 2
  • 25
  • 36