首先,我向你道歉,如果这对你来说,显然是硬件问题,而不是编程问题。如果是,希望我们可以将其迁移到适当的位置。
我有一个长期运行的Web服务程序(任何CPU),它有一大堆数据存储库保存在内存中。有些是每小时刷新一次,有些则不经常刷新。其中一些存储库在从第三方源检索数据后对数据(简单POCO)进行排序。
在蓝色的月亮中,我在AccessViolationException
期间在方法ComputeKeys
内得到Sort
。其中一些存储库在从第三方来源获取数据后使用List<T>.Sort
。
执行这些排序的代码很简单,取决于存储库,但这里有两个例子:
pocos.Sort((a, b) => a.BookingDate.CompareTo(b.BookingDate));
或:
pocos.Sort((a, b) => a.Date.CompareTo(b.Date));
请注意,这些数据集相当大(相对而言)。一个有超过140,000个元素。我将异常记录到数据库中,这是我的日志(时间与我所拥有的另一个日志相关,表明存储库当时正在完成获取数据):
Time Host Data
05/11/2014 16:50 HOST2 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:50 HOST2 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:38 HOST2 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:29 HOST2 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:26 HOST2 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:23 HOST2 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:21 HOST2 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:19 HOST1 {"Name":"IndexOutOfRangeException","Method":"Dispose","Source":"System.Core","Message":"Index was outside the bounds of the array.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"Dispose"},{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:15 HOST1 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:14 HOST1 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:09 HOST1 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 16:08 HOST1 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 15:58 HOST1 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
05/11/2014 15:57 HOST1 {"Name":"AccessViolationException","Method":"ComputeKeys","Source":"System.Core","Message":"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.","StackTrace":{"Lines":[{"LineNumber":0,"Method":"ComputeKeys"},{"LineNumber":0,"Method":"Sort"},{"LineNumber":0,"Method":"MoveNext"},{"LineNumber":0,"Method":".ctor"},{"LineNumber":0,"Method":"ToList"},{"LineNumber":0,"Method":"lambda_method"},{"LineNumber":0,"Method":"Execute"}]}}
正如你所看到的,它几乎同时发生在两个人身上。因此,我想知道这不是一个.NET /编程问题 - 而是一个硬件问题。请注意,它们都是虚拟机,显然以相同的方式构建。单独主机上的两个进程都死亡(我们在主机之间进行负载平衡)。
存储库刷新使用System.Threading.Timer
完成。但是,查看我的存储库日志,没有存储库刷新的时间少于一小时,并且要刷新的最长存储库是11分钟 - 因此没有重叠。
使用ReadWriterLockSlim
类保护对数据的访问。我知道这有点模糊,如果有人需要任何其他信息,我会很乐意提供我能做到的。