在 Mono 和 Ubuntu 14.04 上使用 ASP.NET 5 时出现 NullReferenceException 崩溃

Crash with NullReferenceException using ASP.NET 5 on Mono and Ubuntu 14.04

我们在 ASP.NET 5 on Mono 和 Ubuntu 14.04 上有一个 REST API 运行。我们使用 Mono 是因为我们需要 PostgreSQL 数据库的 NpgSQL 驱动程序。

有一个定期向此 API 发布数据的网络服务器,以及一个可以从此 API 检索数据的网站。

一开始我们使用的是Mono 4.2.1,但是每天都会出现多次NullReferenceExceptions。所以我们恢复到 Mono 4.0.5.1,因为 this article 说 Mono 4.2.1 有问题。

但是,我们仍然每天得到一次异常。完整的异常显示在这里:

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at System.Threading.EventWaitHandle.Reset () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Threading.EventWaitHandle:Reset ()
  at System.Threading.Timer+Scheduler.SchedulerThread () [0x00000] in <filename unknown>:0 
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at System.Threading.EventWaitHandle.Reset () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Threading.EventWaitHandle:Reset ()
  at System.Threading.Timer+Scheduler.SchedulerThread () [0x00000] in <filename unknown>:0 
  at System.Threading.Thread.StartInternal () [0x00000] in <filename unknown>:0 

因为这个旧版本的 Mono 仍然抛出异常,我想它也可能在 ASP.NET 5. 它似乎是框架本身的问题,因为它在System.Threading 包。

有谁知道这是什么,是什么原因造成的?

看起来像这样 bug on xamarin/mono. I'm getting the same issue using Timer. I'm considering either moving to coreclr from mono (I don't use SQL for this particular project, however Npgsql is available on coreclr in alpha builds)。

我还将调查在 Timer 上移动到 Task 是否是一个解决方案。

更新

This 和许多其他帖子表明线程问题已在 linux 内核中修复,这意味着更新内核是一种可能的修复方法。不幸的是,这对我不起作用,因为我使用的是 AWS EC2 HVM 实例。我尝试将 Timer 换成 Task,但这也没有解决问题。

我正在使用与 dnxcore50 不兼容的 SignlR .NET 客户端,所以这阻止了我使用 coreclr。如果我在这方面有任何进展,我会更新这个问题。

更新 2 - 已解决

我将我的 AWS AMI 切换到 Ubuntu,升级了内核,并且不再收到此错误。我使用 this process. This 将内核更新为 3.19.0-41-generic,由上面的原始 xamarin 错误引用,建议它至少需要 3.13.0-65.