首先,如果这对您来说显然是硬件问题,而不是编程问题,我深表歉意。如果是,希望我们可以将其迁移到适当的位置。
我有一个长期运行的 Web 服务程序(任何 CPU),它有一大堆保存在内存中的数据存储库。有些每小时刷新一次,有些则不那么频繁。其中一些存储库在从第 3 方来源检索数据后对数据(简单 POCO)进行排序。
一旦在一个蓝月亮,我AccessViolationException
在ComputeKeys
一个Sort
. 其中一些存储库List<T>.Sort
在从第 3 方来源获取数据后使用。
执行这些类型的代码很简单,并且取决于存储库,但这里有两个示例:
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
类保护对数据的访问。我知道这有点晦涩难懂,如果有人需要任何其他信息,我很乐意提供我所能提供的。