NHIbernateIntegration ISessionManager 与 IIS 线程的问题

发布于 2024-11-26 23:54:33 字数 1357 浏览 2 评论 0 原文

我们在最近升级到 NHibernate 3.10GA、Castle 2.5.2 并使用 Castle.Facilities.NHibernateIntegration 的 ASP.NET 应用程序中发现了一个非常奇怪的问题。我们使用 NHibernateIntegration 中的 ISessionManager 和 Web.SessionWebModule 组件来管理我们的请求响应循环,并使用 isWeb=true 配置它。

我们的应用程序返回一个包含 url 编码参数的页面,该页面随后还会进行一些 Web 服务调用。

该问题间歇性地发生,并表现为 NHibernate.LazyInitializationException - 无法初始化代理 - 无会话错误,由主对象延迟加载多对一关系引起。这表明会话对象在页面的请求-响应循环中丢失。

我们决定调试Castle.Facilities.NHibernation中的OnBeginRequest和OnEndRequest方法,并添加一些调试语句来识别线程。我们发现以下情况:

在出现错误的情况下,OnBeginRequest 中的 threadId 与 OnEndRequest 中的 threadId 不匹配;此外,原始线程似乎正在用于其他请求和响应。当初始页面请求最终返回时,它的 threadid 与它启动时的原始 threadid 不匹配。有人见过这样的事情吗?

这是调试数据。请注意,[9] 表示根据 log4net 的原始线程。请注意,

[9] DEBUG SessionWebModule - On begin request thread id: 9 for MyPage.aspx
[9] DEBUG SessionWebModule - On begin request thread id: 9 for example.ashx
[9] DEBUG SessionWebModule - On end request thread id: 9 example.ashx
[9] DEBUG SessionWebModule - On begin request thread id: 9 for WebService.asmx/js
[9] DEBUG SessionWebModule - On end request thread id: 9 for WebService.asmx/js
[6] ERROR NHibernate.LazyInitializationException - [error message describing relationship] -Could not initialize proxy - no Session.
[6] DEBUG SessionWebModule - On end request thread id: 9 for MyPage.aspx

第一行和最后一行显示页面请求源自线程 9,但在线程 6 中返回。

We are seeing a very strange problem with an ASP.NET application that was recently upgraded to NHibernate 3.10GA, Castle 2.5.2, and using Castle.Facilities.NHibernateIntegration. We are using ISessionManager from NHibernateIntegration with the Web.SessionWebModule component to manage our request response loop, and have it configured with isWeb=true.

Our application returns a page for a url encoded parameter, and this page also subsequently makes some web-service calls.

The problem happens very intermittently, and manifests itself as a NHibernate.LazyInitializationException - Could not initialize proxy - no Session error, caused by the lazy-loading of a many-to-one relationship from the main object. This would suggest that the session object is being lost while in the request-response loop for the page.

We decided to debug the OnBeginRequest and OnEndRequest methods in Castle.Facilities.NHibernation, and added some debugging statements to identify the thread. What we found is the following:

In the cases where there is an error, the threadId in the OnBeginRequest does not match the threadId in the OnEndRequest; and further it appears that the original thread is being used for other requests and responses. When the initial page request is finally returned it's threadid doesn't match the original threadid it was started in. Has anyone seen anything like this?

Here's the debug data. Note the [9] indicates the originating thread according to log4net

[9] DEBUG SessionWebModule - On begin request thread id: 9 for MyPage.aspx
[9] DEBUG SessionWebModule - On begin request thread id: 9 for example.ashx
[9] DEBUG SessionWebModule - On end request thread id: 9 example.ashx
[9] DEBUG SessionWebModule - On begin request thread id: 9 for WebService.asmx/js
[9] DEBUG SessionWebModule - On end request thread id: 9 for WebService.asmx/js
[6] ERROR NHibernate.LazyInitializationException - [error message describing relationship] -Could not initialize proxy - no Session.
[6] DEBUG SessionWebModule - On end request thread id: 9 for MyPage.aspx

Note the first and last line showing that the page request originated in thread 9, but returned in thread 6.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

背叛残局 2024-12-03 23:54:33

我相信您使用的是 IIS 7 和 asp.net 2.0 ?
如果是,请尝试设置 MaxConcurrentRequestsPerCPU

http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0。 ASPX

I beleive you are on IIS 7 and asp.net 2.0 ?
If yes , please try to set MaxConcurrentRequestsPerCPU

http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文