Problem with getting session list

<< Click to Display Table of Contents >>

Navigation:  Forum >

Problem with getting session list

Forum link

 


 

09-09-2020, 09:40 AM:

 

Hi!

 

In order to let some forms be terminated I get the session list with; gSessions.GetList(alst); as one of the last things in  the event IWServerControllerBaseNewSession() in the server control unit

 

But it will almost always not work the second time around, the first time is OK.

 

I've tried to push it to a later time, when the form is up and running (with a timer 5000), but it is the same behaviour.

 

Thx Martin

 

Code:

 

procedure TIWServerController.CleanUpForms(ASession: TIWApplication);

 

var

 

  alst:     TStringList;

 

  aid:      string;

 

  app:      TIWApplication;

 

  exp, al:  boolean;

 

  ok:       boolean;

 

  cnt:      integer;

 

begin

 

  if _LogEnabled then

 

    _Log('Trying to clean-up session list');

 

  try

 

    ok:=false;

 

    cnt:=0;

 

    repeat

 

      alst:=TStringList.Create;

 

      try

 

        gSessions.GetList(alst);

 

        ok:=true;

 

      except

 

        Inc(cnt);

 

        if cnt = 100 then begin

 

          if _LogEnabled then

 

            _Log('**Warning: Could not retrieve session list from IntraWeb platform');

 

          Exit;

 

        end;

 

        Sleep(50);

 

      end;

 

    until ok;

 

    if _LogEnabled then begin

 

      if cnt > 0 then

 

        _Log('Retry count is: ' + IntToStr(cnt));

 

      _Log('Number of sessions currently in the list: ' + IntToStr(alst.Count));

 

    end;

 

    for aid in alst do begin

 

      if aid <> ASession.AppID then begin

 

        app:=gSessions.LookupAndLock(aid, exp, al);

 

        if Assigned(app) and not exp then begin

 

          if app.Name = ASession.Name then begin

 

            if _LogEnabled then

 

              _Log('Session "' + app.AppID + '" will be terminated');

 

            app.Unlock;

 

            app.Terminate;

 

            app.Free;

 

          end else begin

 

            app.Unlock;

 

          end;

 

        end;

 

      end;

 

    end;

 

  finally

 

    alst.Free;

 

  end;

 

  if _LogEnabled then

 

    _Log('Number of sessions (from gSessions): ' + IntToStr(gSessions.Count));

 

end;

 

 

 


 

09-09-2020, 04:55 PM:

 

Hi, see this demo, maybe help you:

 

https://github.com/Atozed/IntraWeb/tree/...essionList

 


 

09-09-2020, 10:24 PM:

 

I don't understand what you are trying to accomplish exactly... You said that you are trying to terminate some forms but you are actually terminating some sessions, correct?

 

How's this method called/triggered? From an user event?

 

You are terminating one specific session from another session (i.e. from Session A you terminate Session B)?

 

If so, the code looks good to me, most of it. But the problem relies on the terminate itself. *Don't free the session yourself*.

 

Code:

 

    if aid <> ASession.AppID then begin

 

      app:= gSessions.LookupAndLock(aid, exp, al);

 

      if Assigned(app) and not exp then begin

 

        if app.Name = ASession.Name then begin

 

          if _LogEnabled then

 

            _Log('Session "' + app.AppID + '" will be terminated');

 

          app.Terminate;  // terminate first

 

     &nbsp;&nbsp; end;

 

     &nbsp;&nbsp; app.Unlock;      // then unlock it. Don't free it!

 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;

 

    end;

 

 

 

After being terminated, session will be collected by the clean up thread which runs in the background, and freed. If you free it yourself, the clean up thread won't be able to do the proper clean up.

 


 

09-10-2020, 11:53 AM:

 

Hi Alexandre!

 

Yes, it is sessions I want to terminate, and yes, terminate session b from session a.

 

I'll try without the free.

 

Thx Martin

 

 

 

Hi again,

 

Yes, that worked, I no longer get errors when reading the list.

 

But the list just keeps growing, the sessions are never freed as far as I can tell.

 

I saw from the examples that you can set a parameter on terminate and that is the new HTML it shows. 

 

Is that a way to go when wanting the forms in a session to be released, I have some forms with big amount of data on them and those dataset are never freed when the form is not freed.

 

What can I do?

 

Thx Martin

 

Edit: I have put a SessionTimeout := 1; and that triggers the release of my forms after a minute at least. Is there a cleaner way?

 

Code:

 

    for aid in alst do begin

 

      if aid <> ASession.AppID then begin

 

        app:=gSessions.LookupAndLock(aid, exp, al);

 

        if Assigned(app) and not exp then begin

 

          if app.Name = ASession.Name then begin

 

            if _LogEnabled then

 

              _Log('Session "' + app.AppID + '" will be terminated');

 

            //app.ReleaseForm(app.Forms[0]);

 

            app.SessionTimeOut:=1;

 

            app.Terminate;

 

          end;

 

          app.Unlock;

 

        end;

 

      end;

 

    end;

 

 

 


 

09-15-2020, 09:11 AM:

 

You shouldn't rely on sessions being destroyed to release forms and/or datasets. If you free a form, regardless of the session state, it will be released. The same for datamodules and any other control. Are you leaving the session with active forms?

 

I'll test this scenario you mentioned and let you know. I'll keep you posted.

 


 

09-15-2020, 09:53 AM:

 

Thank you for looking into it.

 

Yes, the user just leaves the form, and it is actually replaced by another form usually in an iframe (by replacing the url), so I need to have the session and of cause forms to be release in an automated way.

 

I run with the above technique (timeout=1) now and it works very well, what I could which was that there was a way to just terminate the session and automatically free any forms and resources immediately. I have my data set with Owner = the form, so when the form frees the data is freed also. 

 

See the attachment, the IFrame normally points to a ISAPI IntraWeb form with .../$/start/...?companyId=<some id> and the url is just replaced by a new url with a different company id, and therefore the sessions needs to be able to search and terminate the session that was replaced.

 

Thx Martin

 


 

09-20-2020, 04:42 AM:

 

We have a fix in place and a new update should be release soon, which will resolve this problem

 


 

09-20-2020, 05:19 PM:

 

Nice, thank you! Will it be a new terminate and free session immediately function?

 

Martin

 


 

09-22-2020, 11:16 AM:

 

Please update to IW 15.2.18.

 

Answering your question: Yes and no. Terminate() never frees the session immediately. It puts it in the list to be collected by the background thread and it will be freed in 60 seconds or less.