4

我正在使用 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.<---
<---
4

2 回答 2

3

这在https://bitbucket.org/Readify/neo4jclient/issue/70/taskcancelledexception被跟踪为一个问题

诊断和最终的“官方”解决方案将在那里发布。

于 2013-04-02T03:18:43.357 回答
0

我花了几个小时才发现并修复了这个问题。

[编辑]:不要使用Neo4jClient.GraphClient,使用Neo4jClient.BoltGraphClient- 两者都派生自IGraphClient- BoltGraphClient 在幕后不使用 HttpClient 并且速度更快且内存占用更少。

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

我的旧答案+故事:

我将大量 Cypher 查询放入 aList<Task>并通过query.ExecuteWithoutResultsAsync(). Neo4j 服务器一次只能处理这么多,并将请求放入队列中。

我已经确认TaskCanceledException100 秒后被抛出,这是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);
于 2019-02-10T07:59:49.843 回答