Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IWAppFormAsyncPageUnloaded generates exception (Priority support)
#1
Using Rad Studio 10.2.3 with Intraweb 15.2.69

I am trying to use the procedure described below to be sure that the session is really terminated after WebApplication->Terminate() is called.

https://www.atozed.com/2022/12/terminati...-sessions/

I use the code below:


void __fastcall TformMain::IWAppFormAsyncPageUnloaded(TObject *Sender, TStringList *EventParams,
          bool AIsCurrent)
{
    if (AIsCurrent && (WebApplication->ActiveFormCount == 1))
    {
        WebApplication->SelfDestruct();
    }
}


If the user remains inactive more than 1 minute, or maybe less, on the landing page (main form) the application generates the exception attached.

I think the problem is related to the way this function works. The landing page is the only active form. And after the end of the internal timer, 15 s default, it tries to destruct the application even if the Terminate() function was not called.
Even if there is only one form active like in the case of the main form and the application timeout, which is 30 minutes or more, is not reached or Terminate() has not been called, this function should not be triggered!
It cannot rely only on the number of active forms, because the application can have more than 1 form still available and the timeout may have been reached or Terminate() called!


Attached Files Thumbnail(s)
   
Reply
#2
I don't understand your problem here.

> And after the end of the internal timer, 15 s default, it tries to destruct the application even if the Terminate() function was not called.

The only thing that SelfDestruct does it setting the application to be collected by the clean up thread, when the 15 seconds time expires. The clean up thread runs in 1 minutes interval, so it may take from 15 seconds to 1 minute + 15 seconds for it to occur. Once SelfDestruct is called the destruction of that session can only be interrupted within the 15 seconds timeout, if that session receives a new request (this happens automatically).

The posted demo shows an example of how SelfDestruct *could* be used, not how you should use it. It is up to you identify if you can call it or not. There is no way for IntraWeb to understand your own code and decide it it can terminate the session or not.


In that demo, I only have 1 active form at any time - by design - so it makes sense to call SelfDestruct during PageUnload.  As I said above, it is up to you to decide if you should call SelfDestruct or not. The demo is not a strict guide on how to use the feature.
Reply
#3
I have attached a demo. It will be easier to understand.
The error message I posted happens when I run the application with the 64 bit platform. Which unfortunately I can no longer since I migrated to Intraweb XV! I am going to open a new thread for that issue.
To reproduce the issue:
1. Be sure that 32 bit platform is selected
2. Run the application
3. Click on the button: Message "Button clicked" will show as expected
4. Wait at least 2 minutes. Don't perform any activity on teh form during those 2  minutes!
5. Click again on the same button. You will get a timeout error message. Which is not supposed to happen because the session timeout is set to 30 minutes!


Attached Files
.zip   Project3.zip (Size: 58.06 KB / Downloads: 2)
Reply
#4
I'll check your application and get back to you
Reply
#5
I see what you mean here. The problem is, putting everything in a timeline that's how it happens:


Quote:Browser           Server
Click on button
                        OnButtonClick (this will force the page to be rendered again, causing the unload of the old "version" of the page and loading of the new one)
                        Page is rendered -> HTML is generated and sent to the browser
HTML received
Page unloads
                        OnAsyncPageUnloaded
New page loads
                        SelfDestruct is called
                        After 1 minute, IW application is destroyed
Another click
                        Session expired exception

this is how the events happen in an ordered way. And that's why when you click on that button again, IW will consider the session as expired (Because it has been actually destroyed and the browser is requesting a session that doesn't exist anymore)

In order to make this scenario work you can do one of 2 things:

1) don't use sync events. Async events won't trigger PageLoad/PageUnload events

or

2) Create an empty OnAsyncPageLoaded event in that same form. You don't need to add any code to it, just create it. This way IW will trigger an event when the new page loads, terminating the "self destruct sequence"

I'm thinking about the possibility to add (2) automatically to IntraWeb logic so it will be easier to handle this scenario.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)