【问题标题】:C# Neo4jClient TaskCancelled ExceptionC# Neo4jClient 任务取消异常
【发布时间】:2013-03-29 11:45:25
【问题描述】:

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

【问题讨论】:

  • 您能否分享更多关于查询类型和图表复杂性的信息?似乎 Neo4jClient 可能由于查询时间过长而超时。
  • 这很复杂,需要几分钟才能完成。是的,客户端可能超时。但是,错误发生的时间并不一致。

标签: c# exception neo4j neo4jclient


【解决方案1】:

https://bitbucket.org/Readify/neo4jclient/issue/70/taskcancelledexception 正在跟踪此问题

诊断结果和最终的“官方”解决方案将在此处发布。

【讨论】:

    【解决方案2】:

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

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

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

    我的旧答案+故事:

    我将大量 Cypher 查询放入 List&lt;Task&gt; 并通过 query.ExecuteWithoutResultsAsync() 执行它们。 Neo4j 服务器一次只能处理这么多,并将请求放入队列中。

    我已经确认 TaskCanceledException 在 100 秒后被抛出,这是 HttpClient 的默认超时。

    阅读文档后,我想出了如何在图形客户端初始化期间指定无限时间跨度。希望这会节省您的时间。

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      相关资源
      最近更新 更多