我使用Neo4jClient并获得其中发生相当随机的异常使一个相当长的查询Neo4j的数据库。如何解决这一问题?
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.<---
<---
这是正在跟踪作为https://bitbucket.org/Readify/neo4jclient/issue/70/taskcancelledexception问题
诊断和最终的“官方”的决议将在那里公布。
我花了时间来确定这个问题并解决它。
[编辑]:不要使用Neo4jClient.GraphClient
,使用Neo4jClient.BoltGraphClient
- 从IGraphClient
都获得 - 在BoltGraphClient不使用HttpClient的幕后,是方式更快,更占用大量内存。
var BoltGraphClient = new Neo4jClient.BoltGraphClient(url,username,password);
我的老答案+故事:
我把一吨的Cypher查询到List<Task>
并通过query.ExecuteWithoutResultsAsync()
执行它们。该Neo4j的服务器只能处理这么多的时间和将放在一个队列中的请求。
我已经证实,TaskCanceledException
送出100秒后抛出,这是HttpClient
的默认超时。
阅读文档后,我已经想通了如何将graphclient的初始化期间指定了无限的时间跨度。希望这将节省您的时间。
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);