New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The case of the ApplicationContext.ClientContext disappearance #3

Closed
rockfordlhotka opened this Issue Jun 15, 2015 · 21 comments

Comments

Projects
None yet
5 participants
@rockfordlhotka
Member

rockfordlhotka commented Jun 15, 2015

Moving this thread to GitHub. Original is here: http://forums.lhotka.net/forums/t/12029.aspx

@jteneglio

This comment has been minimized.

Show comment
Hide comment
@jteneglio

jteneglio Jun 15, 2015

That's not what I'm doing here, this object in particular is both a root and a child but in different circumstances. In the one I showed here I believe it is a Root , but I doubt that this is related to the issue of the context being lost????

That's not what I'm doing here, this object in particular is both a root and a child but in different circumstances. In the one I showed here I believe it is a Root , but I doubt that this is related to the issue of the context being lost????

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Jun 15, 2015

Member

I'm trying to understand exactly what you are doing so I can create a simple repro of the scenario.

Member

rockfordlhotka commented Jun 15, 2015

I'm trying to understand exactly what you are doing so I can create a simple repro of the scenario.

@jteneglio

This comment has been minimized.

Show comment
Hide comment
@jteneglio

jteneglio Jun 15, 2015

I was thinking of reproducing it in a smaller app so it would be easy to debug... but didn't have the time yet :-D but i'm getting there

I was thinking of reproducing it in a smaller app so it would be easy to debug... but didn't have the time yet :-D but i'm getting there

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Jun 15, 2015

Member

ok, that would be very helpful in trying to solve the problem

Member

rockfordlhotka commented Jun 15, 2015

ok, that would be very helpful in trying to solve the problem

@jteneglio

This comment has been minimized.

Show comment
Hide comment
@jteneglio

jteneglio Jun 15, 2015

In CSLA does every call coming from the WinRT to the server a new thread?

In CSLA does every call coming from the WinRT to the server a new thread?

@jteneglio

This comment has been minimized.

Show comment
Hide comment
@jteneglio

jteneglio Jun 15, 2015

I'm using pretty much the code in The Using CSLA Data Portal Configuration book, Page 94 and up
I've added some Debug Lines and these troubles me (maybe I'm wrong but ), the number at the end of each debug lines are Thread.CurrentThread.ManagedThreadId

2015-06-15 07:03:12.940 Authorize FirstRun In 33 <--- Authorise the first time from UI
2015-06-15 07:03:12.941 CustomePrincipal Load In 33 <--- Load principal
2015-06-15 07:03:12.942 Authorize Else In 33 <-- this is the else of the authorize code??
2015-06-15 07:03:12.943 Authorize Else Out 33 <-- Out of the else ???
2015-06-15 07:03:12.944 CustomIdentity LoadUserData in 33
2015-06-15 07:03:12.959 CustomIdentity LoadUserData Out 33
2015-06-15 07:03:12.960 CustomePrincipal Load Out 33 <-- Finish the load of the principal
DBQueryStop 06/15/2015 11:03:13.226 GenericCount <-- Continue with our code
2015-06-15 07:03:13.230 Authorize FirstRun Out 33 <-- Finish the authorize code
Microsoft.WindowsAzure.ServiceRuntime Verbose: 500 : Role instance status check starting
Microsoft.WindowsAzure.ServiceRuntime Verbose: 502 : Role instance status check succeeded: Ready
2015-06-15 07:03:21.974 Authorize FirstRun In 18
2015-06-15 07:03:21.974 CustomePrincipal Load In 18
2015-06-15 07:03:21.975 Authorize Else In 18
2015-06-15 07:03:21.975 Authorize Else Out 18
2015-06-15 07:03:21.976 CustomIdentity LoadUserData in 18
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/1273337584/ROOT-1-130788827683073723): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'.

2015-06-15 07:03:21.989 CustomIdentity LoadUserData Out 18

---- CONTEXT LOST ----

2015-06-15 07:03:21.991 CustomePrincipal Load Out 18
The thread 0x300 has exited with code 0 (0x0).
The thread 0x2938 has exited with code 259 (0x103).
The thread 0x5288 has exited with code 259 (0x103).
The thread 0x7348 has exited with code 259 (0x103).
The thread 0x5374 has exited with code 259 (0x103).
The thread 0xa88 has exited with code 259 (0x103).
The thread 0x4264 has exited with code 259 (0x103).
The thread 0x4644 has exited with code 259 (0x103).
The thread 0x27a8 has exited with code 259 (0x103).
The thread 0x318c has exited with code 259 (0x103).
The thread 0x710c has exited with code 259 (0x103).
The thread 0x6d44 has exited with code 259 (0x103).
The thread 0x4a94 has exited with code 0 (0x0).
Microsoft.WindowsAzure.ServiceRuntime Verbose: 500 : Role instance status check starting
Microsoft.WindowsAzure.ServiceRuntime Verbose: 502 : Role instance status check succeeded: Ready
2015-06-15 07:04:37.134 Authorize FirstRun Out 18

I'm using pretty much the code in The Using CSLA Data Portal Configuration book, Page 94 and up
I've added some Debug Lines and these troubles me (maybe I'm wrong but ), the number at the end of each debug lines are Thread.CurrentThread.ManagedThreadId

2015-06-15 07:03:12.940 Authorize FirstRun In 33 <--- Authorise the first time from UI
2015-06-15 07:03:12.941 CustomePrincipal Load In 33 <--- Load principal
2015-06-15 07:03:12.942 Authorize Else In 33 <-- this is the else of the authorize code??
2015-06-15 07:03:12.943 Authorize Else Out 33 <-- Out of the else ???
2015-06-15 07:03:12.944 CustomIdentity LoadUserData in 33
2015-06-15 07:03:12.959 CustomIdentity LoadUserData Out 33
2015-06-15 07:03:12.960 CustomePrincipal Load Out 33 <-- Finish the load of the principal
DBQueryStop 06/15/2015 11:03:13.226 GenericCount <-- Continue with our code
2015-06-15 07:03:13.230 Authorize FirstRun Out 33 <-- Finish the authorize code
Microsoft.WindowsAzure.ServiceRuntime Verbose: 500 : Role instance status check starting
Microsoft.WindowsAzure.ServiceRuntime Verbose: 502 : Role instance status check succeeded: Ready
2015-06-15 07:03:21.974 Authorize FirstRun In 18
2015-06-15 07:03:21.974 CustomePrincipal Load In 18
2015-06-15 07:03:21.975 Authorize Else In 18
2015-06-15 07:03:21.975 Authorize Else Out 18
2015-06-15 07:03:21.976 CustomIdentity LoadUserData in 18
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/1273337584/ROOT-1-130788827683073723): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'.

2015-06-15 07:03:21.989 CustomIdentity LoadUserData Out 18

---- CONTEXT LOST ----

2015-06-15 07:03:21.991 CustomePrincipal Load Out 18
The thread 0x300 has exited with code 0 (0x0).
The thread 0x2938 has exited with code 259 (0x103).
The thread 0x5288 has exited with code 259 (0x103).
The thread 0x7348 has exited with code 259 (0x103).
The thread 0x5374 has exited with code 259 (0x103).
The thread 0xa88 has exited with code 259 (0x103).
The thread 0x4264 has exited with code 259 (0x103).
The thread 0x4644 has exited with code 259 (0x103).
The thread 0x27a8 has exited with code 259 (0x103).
The thread 0x318c has exited with code 259 (0x103).
The thread 0x710c has exited with code 259 (0x103).
The thread 0x6d44 has exited with code 259 (0x103).
The thread 0x4a94 has exited with code 0 (0x0).
Microsoft.WindowsAzure.ServiceRuntime Verbose: 500 : Role instance status check starting
Microsoft.WindowsAzure.ServiceRuntime Verbose: 502 : Role instance status check succeeded: Ready
2015-06-15 07:04:37.134 Authorize FirstRun Out 18

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Jun 15, 2015

Member

ASP.NET (that's what's hosting the data portal on the server) handles each client request separately. It uses a thread pool to handle the requests, so it reuses threads all the time, but if more than one client request occurs at the same time then yes, they'll be in different threads.

Member

rockfordlhotka commented Jun 15, 2015

ASP.NET (that's what's hosting the data portal on the server) handles each client request separately. It uses a thread pool to handle the requests, so it reuses threads all the time, but if more than one client request occurs at the same time then yes, they'll be in different threads.

@halloween8

This comment has been minimized.

Show comment
Hide comment
@halloween8

halloween8 Jun 18, 2015

I've build a sample app that replicate the issue I'm having but I cannot add it here (only images are allowed), can I send it to directly you, Rockford?

I've build a sample app that replicate the issue I'm having but I cannot add it here (only images are allowed), can I send it to directly you, Rockford?

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Jun 20, 2015

Member

Put it in onedrive/dropbox/google drive/box/etc. and post a link?

Member

rockfordlhotka commented Jun 20, 2015

Put it in onedrive/dropbox/google drive/box/etc. and post a link?

@jteneglio

This comment has been minimized.

Show comment
Hide comment
@jteneglio

jteneglio Jun 20, 2015

https://onedrive.live.com/?id=F07DB383718C20E5%21139&cid=F07DB383718C20E5&group=0

CSLATestApp.zip

Here is the project I've build that replicates the issue. This project includes a windows azure backend and a Windows 8 front end. You need to start the azure backend first then the front end, In the front end there is 3 buttons, one to login, and 2 others, to replicate the issue, click on the button on the left, then right, then left again. If my conditional break point stayed with the project it should stop in the AuthorizeDataPortal.Authorize on any of those lines, "never" the same one

var userID = ApplicationContext.ClientContext["UserId"];
var userUID = ApplicationContext.ClientContext["UserUID"];
var employeeUID = ApplicationContext.ClientContext["EmployeeUID"];
var languageCode = ApplicationContext.ClientContext["LanguageCode"];
var workingDate = ApplicationContext.ClientContext["WorkingDate"];
var otherData = ApplicationContext.ClientContext["SomeOther"];
var another = ApplicationContext.ClientContext["Another"];
var lastOne = ApplicationContext.ClientContext["LastOne"];

Thanks for looking at it.

https://onedrive.live.com/?id=F07DB383718C20E5%21139&cid=F07DB383718C20E5&group=0

CSLATestApp.zip

Here is the project I've build that replicates the issue. This project includes a windows azure backend and a Windows 8 front end. You need to start the azure backend first then the front end, In the front end there is 3 buttons, one to login, and 2 others, to replicate the issue, click on the button on the left, then right, then left again. If my conditional break point stayed with the project it should stop in the AuthorizeDataPortal.Authorize on any of those lines, "never" the same one

var userID = ApplicationContext.ClientContext["UserId"];
var userUID = ApplicationContext.ClientContext["UserUID"];
var employeeUID = ApplicationContext.ClientContext["EmployeeUID"];
var languageCode = ApplicationContext.ClientContext["LanguageCode"];
var workingDate = ApplicationContext.ClientContext["WorkingDate"];
var otherData = ApplicationContext.ClientContext["SomeOther"];
var another = ApplicationContext.ClientContext["Another"];
var lastOne = ApplicationContext.ClientContext["LastOne"];

Thanks for looking at it.

@jteneglio

This comment has been minimized.

Show comment
Hide comment
@jteneglio

jteneglio Jun 27, 2015

Any luck replicating?

Any luck replicating?

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Jun 29, 2015

Member

I think the business rule idea is a red herring. I put a breakpoint in the rule and it is never executed.

Member

rockfordlhotka commented Jun 29, 2015

I think the business rule idea is a red herring. I put a breakpoint in the rule and it is never executed.

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Jun 29, 2015

Member

Your breakpoint didn't make it to me, and I don't see what's failing for you. I put a couple lines at the very top of the Authorize() method

      var tmp = Csla.ApplicationContext.LocalContext["FirstRun"];
      var tmpuser = ApplicationContext.ClientContext["UserId"];

And those two fields seem to be containing the correct values as I click the buttons.

Member

rockfordlhotka commented Jun 29, 2015

Your breakpoint didn't make it to me, and I don't see what's failing for you. I put a couple lines at the very top of the Authorize() method

      var tmp = Csla.ApplicationContext.LocalContext["FirstRun"];
      var tmpuser = ApplicationContext.ClientContext["UserId"];

And those two fields seem to be containing the correct values as I click the buttons.

@jteneglio

This comment has been minimized.

Show comment
Hide comment
@jteneglio

jteneglio Jun 29, 2015

Indeed the business rule is not the problem, I've put a conditional break point with this in it

Csla.ApplicationContext.ClientContext.Count == 0

on line 44 through 51 in AuthorizeDataPortal

And sometimes it stops on the second, some times on the third....

Indeed the business rule is not the problem, I've put a conditional break point with this in it

Csla.ApplicationContext.ClientContext.Count == 0

on line 44 through 51 in AuthorizeDataPortal

And sometimes it stops on the second, some times on the third....

@rockfordlhotka

This comment has been minimized.

Show comment
Hide comment
@rockfordlhotka

rockfordlhotka Jun 29, 2015

Member

So you are saying that some code is running during the Authorize() call that is clearing the context?

Member

rockfordlhotka commented Jun 29, 2015

So you are saying that some code is running during the Authorize() call that is clearing the context?

@jteneglio

This comment has been minimized.

Show comment
Hide comment
@jteneglio

jteneglio Jun 29, 2015

It would seem yes

It would seem yes

@jteneglio

This comment has been minimized.

Show comment
Hide comment
@jteneglio

jteneglio Jul 4, 2015

Hard issue or is it me :-)

Hard issue or is it me :-)

@fmonroe

This comment has been minimized.

Show comment
Hide comment
@fmonroe

fmonroe Jul 5, 2015

Hi there Rocky. Jean works with me. This is a rather big thing for us. You could say that we "bet the company" on CSLA (perhaps more than the Company :) I've been a fan of CSLA for more than a decade but this is our first app on the WIndows8/Modern/WinRT "platform". Our app is a multi-user app that has difficulties being multi-users.
Any help would be much appreciated. Is there any clarification or anything else I (or Jean) can do to help you help us? Thank you very much.
PS. We met in Vegas last year. I do remember you, but I understand if you don't remember me ;) Cheers!

fmonroe commented Jul 5, 2015

Hi there Rocky. Jean works with me. This is a rather big thing for us. You could say that we "bet the company" on CSLA (perhaps more than the Company :) I've been a fan of CSLA for more than a decade but this is our first app on the WIndows8/Modern/WinRT "platform". Our app is a multi-user app that has difficulties being multi-users.
Any help would be much appreciated. Is there any clarification or anything else I (or Jean) can do to help you help us? Thank you very much.
PS. We met in Vegas last year. I do remember you, but I understand if you don't remember me ;) Cheers!

@jonnybee

This comment has been minimized.

Show comment
Hide comment
@jonnybee

jonnybee Jul 5, 2015

Member

Hi,

I have been able to reproduce the issue and after hours of debugging and instrumenting the code I believe I have found the underlying issue and fix. Email is sent to Rocky.

The issue is caused by the MobileRequestProcessor on the server side that does not set ExecutionLocation to Server.

If you have the source code available you may make the change youselves to verify that this solves your issue:
Change this method in Csla.Server.Hosts.Mobile.MobileRequestProcessor:

private void SetContext(IMobileRequest request)
{
  // JOB: Serverside portal should set execution locations
  ApplicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
  ApplicationContext.SetLogicalExecutionLocation(ApplicationContext.LogicalExecutionLocations.Server);

  ApplicationContext.SetContext(request.ClientContext, request.GlobalContext);
  if (ApplicationContext.AuthenticationType != "Windows")
    ApplicationContext.User = request.Principal;
  SetClientCultures(request);
}
Member

jonnybee commented Jul 5, 2015

Hi,

I have been able to reproduce the issue and after hours of debugging and instrumenting the code I believe I have found the underlying issue and fix. Email is sent to Rocky.

The issue is caused by the MobileRequestProcessor on the server side that does not set ExecutionLocation to Server.

If you have the source code available you may make the change youselves to verify that this solves your issue:
Change this method in Csla.Server.Hosts.Mobile.MobileRequestProcessor:

private void SetContext(IMobileRequest request)
{
  // JOB: Serverside portal should set execution locations
  ApplicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
  ApplicationContext.SetLogicalExecutionLocation(ApplicationContext.LogicalExecutionLocations.Server);

  ApplicationContext.SetContext(request.ClientContext, request.GlobalContext);
  if (ApplicationContext.AuthenticationType != "Windows")
    ApplicationContext.User = request.Principal;
  SetClientCultures(request);
}
@fmonroe

This comment has been minimized.

Show comment
Hide comment
@fmonroe

fmonroe Jul 5, 2015

Thank you so much!!!!!! We'll let you know soon!

fmonroe commented Jul 5, 2015

Thank you so much!!!!!! We'll let you know soon!

@jteneglio

This comment has been minimized.

Show comment
Hide comment
@jteneglio

jteneglio Jul 5, 2015

A BIG THANKS to you Jonny, i tried the patch you just post and it seem to have fix it. NICE!!!!stop

A BIG THANKS to you Jonny, i tried the patch you just post and it seem to have fix it. NICE!!!!stop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment