Quit WebSession without quitting WebApp?

I’m trying to implement error catching like this:

WebSession.UnhandledException 
    // log the error
   ...
  // terminate this session
   self.quit
  // don't terminate the app
  return true

But this doesn’t seem to work - the WebApp always quits too.

Hmm - in fact, when stepping through this code in the debugger, the IDE just crashed.

The IDE crash has been reported as <https://xojo.com/issue/38388> but I’m more interested in the issue of “how to end a session without ending the app”.

More info: something is definitely wrong with the behavior of WebSession.Quit - and it also appears to be related to whether or not the IDE has “break on exceptions” enabled or not. I’m seeing situations where WebSession.Quit will quit the session, but not the WebApp, and other times the WebApp will quit, too. It seems somewhat random. Anyone dealt with this?

WebSession.Quit is working as expected in Xojo 2015r1 and OS X 10.10.2. The expectation is for WebSession to quit but not WebApplication. Calling Self.Quit in the WebSession.TimedOut event, Session.Quit in a method on a WebPage and Self.SessionAtIndex(AnIntegerValue).Quit in a method on WebApplication all work. None of the WebSession.Quit calls are from WebSession.UnhandledException. Perhaps the issue you’re experiencing is specific to that method and event combination.

Thanks Frederick, if you have the chance, could you test what happens in 2015 R1 with calling Self.Quit inside Session.UnhandledException?

I can reproduce this in a trivial demo project: <https://xojo.com/issue/38390>

And the odd behavior happens in both 2014 R3 and 2015 R1…

Why call Session.Quit from Session.UnhandledException? Seems a little nonsensical to me.

If Session.UnhandledException returns False, then the exception is not handled, and the entire app quits.
If Session.UnhandledException returns True, then the exception is considered handled, and the session keeps running.

What I’m trying to do is option 3:
If Session.UnhandledException returns True, then the exception is considered handled and the app doesn’t quit, HOWEVER we want to end the session because something went wrong.

The goal here is to have a somewhat fault-tolerant server : if an individual session dies, the user will be logged off, but the server itself won’t go down.

Testing the project you attached to <https://xojo.com/issue/38390> in Xojo 2015r1 on OS X 10.10.2, WebApplication continues to run regardless of which WebButton is clicked and whether or not Break On Exceptions is checked. While testing, I maintained at least two connections using tabs in Safari 8.0.3, otherwise WebApplication would quit due to the lack of any active connections. In your testing, did you maintain multiple connections to keep the WebApplication running in the IDE?

[quote=171202:@Michael Diehr]I’m trying to implement error catching like this:

WebSession.UnhandledException 
    // log the error
   ...
  // terminate this session
   self.quit
  // don't terminate the app
  return true

But this doesn’t seem to work - the WebApp always quits too.

Hmm - in fact, when stepping through this code in the debugger, the IDE just crashed.

The IDE crash has been reported as <https://xojo.com/issue/38388> but I’m more interested in the issue of “how to end a session without ending the app”.[/quote]

Session.Quit still seems buggy. I have a CGI app that creates ghost sessions that never die, and Session.Quit does not help. So as advised by Greg a while ago, now I showURL to an HTML page, and the session dies by itself. It work fine. Maybe you can use the same trick ?

Wait… what? A WebApplication quits when it has no sessions active? I know this certainly is not true in standalone web apps - Is this something that only happens in the IDE? Where is this documented? Why?

Oh, is this due to http://documentation.xojo.com/index.php/WebApplication.AutoQuit ? If so, then this is rather confusing, as the documentation is mute on what the behavior when debugging in the IDE is supposed to be.

Ok, it does indeed seem that when running a WebApp in the IDE, WebApp.AutoQuit = true. So this means I was very confused about all the testing.

Adding this code:

WebApp.Open 
 #if DebugBuild
    self.AutoQuit = False
  #endif

Will make it so testing in the IDE is more like testing a standalone app.

It does. Otherwise you’d have no default way to quit the app cleanly for profiling and such.

For debugging, we also shortened the time between the last session dying and the app quitting. You can adjust these by setting:

app.Timeout = 60 // Number of seconds to wait after the last session quits before the app itself quits. app.SessionTimeout = 180 // Number of seconds a session will stay alive after it has lost contact with the client

When you are debugging, these properties are set to 1 and 10 respectively, but you can set them to anything you want. I’d suggest doing it in App.Open though.