Note that there are some explanatory texts on larger screens.

plurals
  1. POSession is closed!, Object name: ISession - Rhino Security and Sharp Architecture
    primarykey
    data
    text
    <p>I'm having an issue with a closed, but not disposed NHibernate Session, inside Rhino Security. It looks like Windsor hands off the closed session to the AuthorizationService. The problem doesn't occur until the second call to the method below. The first call works fine. The Windsor container has everything configured for a Transient lifestyle.</p> <p>I'm using Sharp Architecture 2.0 RC.</p> <p>The calling service/task is handled by the same Windsor container as the AuthorizationRepository.</p> <p>Any thoughts as to what is causing the issue would be greatly appreciated?</p> <pre><code>namespace Rhino.Security.Services { public class AuthorizationRepository : IAuthorizationRepository { //... public virtual UsersGroup[] GetAssociatedUsersGroupFor(IUser user) { ICollection&lt;UsersGroup&gt; usersGroups = SecurityCriterions.AllGroups(user) .GetExecutableCriteria(session) //This session is closed and not connected when the line executes .AddOrder(Order.Asc("Name")) .SetCacheable(true) .List&lt;UsersGroup&gt;(); return usersGroups.ToArray(); //This line of code (ICollection...) throws the exception!!! } //... }} </code></pre> <p>The ISession Facility looks like the following:</p> <pre><code>container.AddFacility&lt;FactorySupportFacility&gt;() .Register(Component.For&lt;ISession&gt;() .UsingFactoryMethod(() =&gt; NHibernateSession.Current) .LifeStyle.Is(LifestyleType.Transient)); </code></pre> <p>The Rhino Security Component Registration looks like the following:</p> <pre><code>private static void AddRhinoSecurityComponentsTo(IWindsorContainer container) { // For RhinoSecurity container.Register( Component.For&lt;IAuthorizationService&gt;() .ImplementedBy&lt;AuthorizationService&gt;() .LifeStyle.Is(LifestyleType.Transient), Component.For&lt;IAuthorizationRepository&gt;() .ImplementedBy&lt;AuthorizationRepository&gt;() .LifeStyle.Is(LifestyleType.Transient), Component.For&lt;IPermissionsBuilderService&gt;() .ImplementedBy&lt;PermissionsBuilderService&gt;() .LifeStyle.Is(LifestyleType.Transient), Component.For&lt;IPermissionsService&gt;() .ImplementedBy&lt;PermissionsService&gt;() .LifeStyle.Is(LifestyleType.Transient) ); } </code></pre> <p>The method calling the AuthorizationService is one of the two following, depending:</p> <p>SecurityHelper(1):</p> <pre><code>public static bool IsAllowed(string operation) { User user = (User)HttpContext.Current.Session["User"]; IAuthorizationService authorizationService = ServiceLocator.Current.GetInstance&lt;IAuthorizationService&gt;(); return authorizationService.IsAllowed(user as User, operation); } </code></pre> <p>SecurityTasks(2):</p> <pre><code>public UsersGroup[] GetAssociatedUsersGroupFor(IUser user) { return authRepository.GetAssociatedUsersGroupFor(user); } </code></pre> <p>The NHibernate Init looks like the following:</p> <pre><code>NHibernateSession.Init( this.webSessionStorage, new[] { Server.MapPath("~/bin/ClinicalTrials.Infrastructure.dll") }, new AutoPersistenceModelGenerator().Generate(), Server.MapPath("~/NHibernate.config")); </code></pre> <p>The ysod looks like the following:</p> <pre><code>Session is closed! Object name: 'ISession'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ObjectDisposedException: Session is closed! Object name: 'ISession'. Source Error: Line 329: public virtual UsersGroup[] GetAssociatedUsersGroupFor(IUser user) Line 330: { Line 331: ICollection&lt;UsersGroup&gt; usersGroups = Line 332: SecurityCriterions.AllGroups(user) Line 333: .GetExecutableCriteria(session) Source File: ...\Rhino.Security - nHibernate 3.1\Rhino.Security\Services\AuthorizationRepository.cs Line: 331 Stack Trace: [ObjectDisposedException: Session is closed! Object name: 'ISession'.] NHibernate.Impl.AbstractSessionImpl.ErrorIfClosed() +124 NHibernate.Impl.AbstractSessionImpl.CheckAndUpdateSessionStatus() +31 NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) +173 NHibernate.Impl.CriteriaImpl.List(IList results) +80 NHibernate.Impl.CriteriaImpl.List() +105 Rhino.Security.Services.AuthorizationRepository.GetAssociatedUsersGroupFor(IUser user) in ...\Rhino.Security - nHibernate 3.1\Rhino.Security\Services\AuthorizationRepository.cs:331 ClinicalTrialsAdmin.Tasks.SecurityTasks.GetAssociatedUsersGroupFor(IUser user) in ...\Source\Admin\Solutions\ClinicalTrialsAdmin.Tasks\SecurityTasks.cs:89 ClinicalTrialsAdmin.Web.Mvc.Controllers.Permission.PermissionController.ShowUsers() in ...\Source\Admin\Solutions\ClinicalTrialsAdmin.Web.Mvc\Controllers\Permission\PermissionController.cs:228 lambda_method(Closure , ControllerBase , Object[] ) +96 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27 System.Web.Mvc.&lt;&gt;c__DisplayClass15.&lt;InvokeActionMethodWithFilters&gt;b__12() +55 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263 System.Web.Mvc.&lt;&gt;c__DisplayClass17.&lt;InvokeActionMethodWithFilters&gt;b__14() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263 System.Web.Mvc.&lt;&gt;c__DisplayClass17.&lt;InvokeActionMethodWithFilters&gt;b__14() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343 System.Web.Mvc.Controller.ExecuteCore() +116 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 System.Web.Mvc.&lt;&gt;c__DisplayClassb.&lt;BeginProcessRequest&gt;b__5() +37 System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0() +21 System.Web.Mvc.Async.&lt;&gt;c__DisplayClass8`1.&lt;BeginSynchronous&gt;b__7(IAsyncResult _) +12 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 System.Web.Mvc.&lt;&gt;c__DisplayClasse.&lt;EndProcessRequest&gt;b__d() +50 System.Web.Mvc.SecurityUtil.&lt;GetCallInAppTrustThunk&gt;b__0(Action f) +7 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.Mvc.&lt;&gt;c__DisplayClassa.&lt;EndProcessRequest&gt;b__9() +23 System.Web.Mvc.&lt;&gt;c__DisplayClass4.&lt;Wrap&gt;b__3() +12 System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +38 System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Action action) +65 System.Web.Mvc.ServerExecuteHttpHandlerAsyncWrapper.EndProcessRequest(IAsyncResult result) +71 System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1072 [HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.] System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +3058371 System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +77 System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +28 System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +22 System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +497 System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName) +34 ASP._Page_Views_Administration_Default_cshtml.Execute() in ...\Source\Admin\Solutions\ClinicalTrialsAdmin.Web.Mvc\Views\Administration\Default.cshtml:44 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76 System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +220 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +303 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13 System.Web.Mvc.&lt;&gt;c__DisplayClass1c.&lt;InvokeActionResultWithFilters&gt;b__19() +23 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260 System.Web.Mvc.&lt;&gt;c__DisplayClass1e.&lt;InvokeActionResultWithFilters&gt;b__1b() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260 System.Web.Mvc.&lt;&gt;c__DisplayClass1e.&lt;InvokeActionResultWithFilters&gt;b__1b() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260 System.Web.Mvc.&lt;&gt;c__DisplayClass1e.&lt;InvokeActionResultWithFilters&gt;b__1b() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343 System.Web.Mvc.Controller.ExecuteCore() +116 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 System.Web.Mvc.&lt;&gt;c__DisplayClassb.&lt;BeginProcessRequest&gt;b__5() +37 System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0() +21 System.Web.Mvc.Async.&lt;&gt;c__DisplayClass8`1.&lt;BeginSynchronous&gt;b__7(IAsyncResult _) +12 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 System.Web.Mvc.&lt;&gt;c__DisplayClasse.&lt;EndProcessRequest&gt;b__d() +50 System.Web.Mvc.SecurityUtil.&lt;GetCallInAppTrustThunk&gt;b__0(Action f) +7 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8963149 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +184 </code></pre> <p>It appears that the session is closed somewhere in the transition between the _layout.cshtml page and the inheriting .cshtml page. Is this normal? Am I missing some way to control how and when the session is closed, or how Windsor handles the session?</p> <p>Last session open call stack:</p> <pre><code>&gt; Rhino.Security.DLL!Rhino.Security.Services.AuthorizationRepository.AuthorizationRepository(NHibernate.ISession session) Line 26 C# [External Code] Microsoft.Practices.ServiceLocation.DLL!Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(System.Type serviceType, string key) Line 49 + 0x11 bytes C# Microsoft.Practices.ServiceLocation.DLL!Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance&lt;Rhino.Security.Interfaces.IAuthorizationService&gt;() Line 90 + 0x4a bytes C# ClinicalTrialsAdmin.Web.Mvc.DLL!ClinicalTrialsAdmin.Web.Mvc.Controllers.Shared.SecurityHelper.IsAllowed(string operation) Line 38 + 0x24 bytes C# App_Web_1yy2q1b3.dll!ASP._Page_Views_Permission_UserGridView_cshtml.Execute() Line 179 + 0xb bytes C# [External Code] App_Web_3rkjaiom.dll!ASP._Page_Views_Administration_Default_cshtml.Execute() Line 44 + 0x1f bytes C# [External Code] Session is still open! </code></pre> <p>First session closed call stack:</p> <pre><code>&gt; Rhino.Security.DLL!Rhino.Security.Services.AuthorizationRepository.AuthorizationRepository(NHibernate.ISession session) Line 26 C# [External Code] Microsoft.Practices.ServiceLocation.DLL!Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(System.Type serviceType, string key) Line 49 + 0x11 bytes C# Microsoft.Practices.ServiceLocation.DLL!Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance&lt;Rhino.Security.Interfaces.IAuthorizationService&gt;() Line 90 + 0x4a bytes C# ClinicalTrialsAdmin.Web.Mvc.DLL!ClinicalTrialsAdmin.Web.Mvc.Controllers.Shared.SecurityHelper.IsAllowed(string operation) Line 38 + 0x24 bytes C# App_Web_paosedyq.dll!ASP._Page_Views_Shared__Layout_cshtml.Execute() Line 222 + 0x98 bytes C# [External Code] Session is now closed! </code></pre> <p>I'm still having this issue, and haven't found any new solutions. Every once in a while, the session just ends up closed inside the Rhino Security code. As such, Rhino throws a System.ObjectDisposedException.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload