asp.net – .NET中的堆栈溢出将IIS发送到100%的CPU使用率 – 为什么没有StackOverflowException?

我在Server 2008 R2 IIS 7.5上运行的ASP.NET应用程序中有一些代码.每当我加载一个特定页面,它将永久挂起,并将IIS发送到100%的cpu使用率.我最终跟踪了这个问题.
public string Comments
{
    get { return this.Comments; }
}

糟糕 – 应该已经返回this.Photo.Comments.所以我的问题是,为什么.NET不会生成一个StackOverflowException,而是让IIS以100%的cpu运行的时间远远超过了应用程序的时间.在我使用.NET编程的经验中,在执行上述操作时,需要几秒甚至更少的时间才能获得StackOverflowException.那么在IIS上还能运行几乎30分钟呢?

解决方法

可能的JIT编译器优化了一个方法调用YourClass :: get_Comments()(这是IL将是什么样子),并内联代码与jmp(或任何x86汇编程序将是)循环构造,因为没有任何值被传递.只是一个想法.

这篇旧文章值得一看:

07000

“A typical example of a really good
candidate for inlining is a property
getter/setter. These are usually
really small methods that usually just
do a memory fetch or store,so it’s
usually a size and speed win to inline
them.”

正如:

07001

我也用一个简单的控制台应用程序来转载:

class Program
{
  static void Main(string[] args)
  {
    MyClass mc = new MyClass();
    string s = mc.Comments;
  }
}

public class MyClass
{
  public string  Comments
  {
    get { return this.Comments; }
  }
}

关闭优化的调试模式下,我收到一个堆栈溢出异常.打开Jit Optimisations并编译发布版本后,该应用程序将永远运行.这表明可能发生了一个循环的内联.

C#2.0,3.0和4.0也是如此.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....