NHibernateIntegration Facilities callcontext work with multiple threads

14 views
Skip to first unread message

Huy Tran

unread,
Jan 16, 2019, 7:49:47 AM1/16/19
to Castle Project Users
I am using .Net v4.7.2, 
Castle core :2.5.1.0
Castle.Facilities.AutoTx 2.5.0.0
Castle.Facilities.Logging 2.5.1.0
Castle.Services.Logging.Log4netIntegration 2.5.1.0
Castle.Services.Transaction 2.5.0.0
Castle.Windsor 2.5.1.0

There are no error for compatible version. All of them work fine.

I am using NHibernateIntegration in my MVC app. I facts an error about concurrent request. 
If I tried request multiple request at same time. The first coming request will success. The after request will fail all.

Then I download the source code of NHibernateIntegration and add to my solution to debug the source code.
I found out the rootcause issue as:

thread id: 15 OnBeginRequest /Main/DynamicForms/HanldlePost session id e499e4ac-c793-4761-8e5a-96dff0277b79 
thread id: 15 HanldlePost /Main/DynamicForms/HanldlePost session id e499e4ac-c793-4761-8e5a-96dff0277b79
thread id: 23 OnBeginRequest /Main/DynamicForms/HanldlePost session id b066f2b3-0c11-4198-9e81-b0e028022fe7 
thread id: 15 OnEndRequest /Main/DynamicForms/HanldlePost session id e499e4ac-c793-4761-8e5a-96dff0277b79 
thread id: 26 OnBeginRequest /Main/Root.css session id 159faeb1-522f-4fdb-9c5b-7fc1630349a5 
thread id: 26 OnEndRequest /Main/Root.css session id 159faeb1-522f-4fdb-9c5b-7fc1630349a5 
thread id: 25 OnBeginRequest /Main/!jquery/js/jquery-1.5.2.min.js session id ddc8af7e-896f-49de-9b61-b726e03d07e5 
thread id: 22 OnBeginRequest /Main/!jquery/jqsuite/js/grid.locale-en.js session id 6cb3ca73-b895-4df1-976e-ce23a3f81d83 
thread id: 18 OnBeginRequest /Main/!DynamicForms/Content/DynamicForm.css session id bd6a5e1e-4b97-49d5-a429-21a34e08e705 
thread id: 23 OnBeginRequest /Main/!jquery/jqsuite/css/ui.jqgrid.css session id 52b58d40-c5b9-4b9f-a1a1-44d47d683553 
thread id: 16 OnBeginRequest /Main/!jquery/js/jquery.autosize.js session id 5feac7aa-89e3-4ba7-97e0-075632decaa1 
thread id: 25 OnEndRequest /Main/!jquery/js/jquery-1.5.2.min.js session id ddc8af7e-896f-49de-9b61-b726e03d07e5 
thread id: 16 OnEndRequest /Main/!jquery/js/jquery.autosize.js session id 5feac7aa-89e3-4ba7-97e0-075632decaa1 
thread id: 22 OnEndRequest /Main/!jquery/jqsuite/js/grid.locale-en.js session id 6cb3ca73-b895-4df1-976e-ce23a3f81d83 
thread id: 18 OnEndRequest /Main/!DynamicForms/Content/DynamicForm.css session id bd6a5e1e-4b97-49d5-a429-21a34e08e705 
thread id: 15 OnBeginRequest /Main/!jquery/css/redmond/jquery-ui-1.8.12.custom.css session id 9ffb9280-4fe1-49ea-9b35-a23505a04d0e 
thread id: 23 OnEndRequest /Main/!jquery/jqsuite/css/ui.jqgrid.css session id 52b58d40-c5b9-4b9f-a1a1-44d47d683553 
thread id: 18 OnBeginRequest /Main/!jquery/js/spell.js session id ff8a65cd-46cc-4b79-aec1-dc36b05cd496 
thread id: 14 HanldlePost /Main/DynamicForms/HanldlePost session id b066f2b3-0c11-4198-9e81-b0e028022fe7

The above log represents for 2 requests which are in 2 different color. The fist come request will be processed until finish then the second request will be resumed.
The second request only run the OnBeginRequest  then stop and wait until the previous request done.
I am not sure that cause by my wrong setting or that is standard behavior of MVC.

I investigate 2 class of NHibernateIntegration: Castle.Facilities.NHibernateIntegration.Components.Web/SessionWebModule and Castle.Facilities.NHibernateIntegration.SessionStores/AbstractSessionStore
onbegin.PNG
This function will add a session to HttpContext of each request.
I double check HanldlePost  and OnBeginRequest. These method runs in separate thread, but stored session in httpcontext has kept.

callctxStore.PNG
OnBeginRequest  will store the dictionary to CallContext, but HanldlePost   run in other thread, So HanldlePost   will try to get dictionary. That is not exist

Can anyone help me for this issue.
Any help are very appreciated.

Thanks








Reply all
Reply to author
Forward
0 new messages