[英]C# Neo4jClient TaskCancelled Exception
我正在使用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服务器一次只能处理这么多,并将请求放入队列中。
我已经确认在100秒后抛出TaskCanceledException
,这是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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.