Fórumok

Session Expires even i am working on the page.

Azhar md, módosítva 9 év-val korábban

Session Expires even i am working on the page.

Junior Member Bejegyzések: 59 Csatlakozás dátuma: 2014.12.01. Legújabb bejegyzések
Hi Everyone
My session expires even when i am working on the page.
I have tried many solutions but nothing works for me

Kindly help me out
I am using liferay 6.2

Thanks in advance.
thumbnail
Samuel Kong, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page.

Liferay Legend Bejegyzések: 1902 Csatlakozás dátuma: 2008.03.10. Legújabb bejegyzések
Although you may be working on a page, if you aren't making request to the server, the server will think you're inactive and your session will expire. The easiest solution is probably to just extend the session timeout length. If that doesn't work, you'll need to add some customization. Probably something involving making an AJAX call to the server every time a user does a mousedown event.
Azhar md, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page.

Junior Member Bejegyzések: 59 Csatlakozás dátuma: 2014.12.01. Legújabb bejegyzések
Hi Samuel,
Thank you for your response
I dont have ajax in my programming then wat i do..

Although you may be working on a page, if you aren't making request to the server, the server will think you're inactive and your session will expire.


I am working on websockets it fetches data from db for every 10 secs..
Then how it cant be inactive??
correct me if i am wrong,

Kindly help

Thanks,
Azhar
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page. (Válasz)

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Azhar md:
I am working on websockets it fetches data from db for every 10 secs. Then how it cant be inactive?


websockets fetching data from db is not access to the Liferay server.

You guys (you and all of your friends asking similar questions basically around a client browser sitting open for more than 30 minutes, session times out because of no activity and you don't know why) need a little schooling, so here we go...

When you log into liferay, you are hitting the Liferay web application, the ROOT webapp from tomcat. Liferay renders an HTML page based on combining all fragments from the portlets (may be separate web apps) on the page. As the user clicks around through the page choosing menus, submitting forms, logs in, whatever, this cycle keeps refreshing the Liferay web app session, the primary session container. Every request that follows this pattern, when ROOT is done rendering the response the expiration clock is reset on the session. If a new request comes in to the ROOT war before that clock expires, session gets extended and all is good, but if another request doesn't come in before that clock expires, the session is invalidated and is lost.

Now if you create a portlet that, say, uses AJAX against a special servlet in your web app (WAR) file, or you're using websockets against your servlet, or maybe it's a web service call against the same internal server or perhaps you have a load balancer which is sending requests to other servers based upon URL pattern matching, whatever. If you create any of these things which bypass the request/response cycle from the previous section, well then you're not submitting a request which will tell Liferay to extend it's session.

Myself and others, we have responded and said that all you guys have to do is invoke Liferay.Session.extend() in the browser. This is a special javascript method that submits a specially crafted request to the ROOT web app to extend the session on the server side, thus restarting the expiration clock. Perhaps in your code that's polling every 10 seconds, perhaps in there you invoke the Liferay.Session.extend() every 60th invocation (so you don't kill Liferay). Perhaps you use just a simple javascript timer to invoke the Liferay.Session.extend() every 10 minutes, and you start the timer when the doc is ready using standard javascript methods, whatever.

Doesn't matter how, but all you need to do is invoke Liferay.Session.extend() on the client side and all will be taken care of.

You guys all seem to think that if your code is making *any* sort of call in the browser that this somehow magically will get Liferay to extend the session, but I'd think by now that you would have figured out that no, it is not *any* calls that are extending the session but there are some that do.

And before you asked, like one of the other current threads about this topic have, why there isn't some sort of 'automatic' or 'magical' session stuff built into a page to keep it alive, well it all comes down to the standard use case. The standard use case is that the session should only be extended when a user submits a request to the ROOT web app on the server, otherwise we want the server to expire the session, close the 'security' door, and discard unused resources. Your use case about keeping everything open when the user is sitting on the page, well that's an antipattern that we typically do not want to allow (imagine one of your users walks into an internet cafe, opens the browser to get on this page, but then gets up and walks out - the browser is still up and anyone or everyone can sit down and have instant access to your system and is still logged in as the user).
Azhar md, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page.

Junior Member Bejegyzések: 59 Csatlakozás dátuma: 2014.12.01. Legújabb bejegyzések
Hi Legend,

That was the best explanantion i ever had..
Thank you sooo much..
Hats off...

Thanks again,..
thumbnail
Stian Sigvartsen, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page.

Regular Member Bejegyzések: 103 Csatlakozás dátuma: 2010.08.27. Legújabb bejegyzések
David, great explanation and I agree with everything. Looks Liferay 6.2 does provide some support for auto-extending the sessions without writing code, but only in the EE version. Azhar, unsure if you're running 6.2 CE or EE, but either way this feature looks like it's going to be in both CE & EE in 7.0.

For details see LPS-45084 and related commit e7a0e76b6c98128756f46ca22e8b890f03945dc1

But basically in portal.properties you add the following:
session.timeout.auto.extend=true


-Stian
Azhar md, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page.

Junior Member Bejegyzések: 59 Csatlakozás dátuma: 2014.12.01. Legújabb bejegyzések
Hi Stian,
Thanks for your response.
We are using liferay-portal-6.2-ce-ga2.. and we worked according to david suggestion it works great.
If problem persists we will go on your suggestion, thanks stian

BR,
Azhar
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page.

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Stian Sigvartsen:
But basically in portal.properties you add the following:
session.timeout.auto.extend=true


That's actually been in Liferay for awhile, Stian, but you have to be aware of the implications... If you auto extend the sessions, they stay alive as long as the browser is up. That may or may not be what you want on your site, especially if you have heavy session storage. For example, I keep a browser open all the time on slashdot; they know this kind of thing happens and I'm sure they stay away from session storage otherwise their systems would be consistently overwhelmed.

IMHO session storage is a crutch anyway and should simply be avoided. It's easy to say that in a pure sense, but reality sets in and some amount of session storage is sometimes necessary, but it still should be used judiciously...
Masud Ahamed, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page.

New Member Bejegyzés: 1 Csatlakozás dátuma: 2015.01.21. Legújabb bejegyzések
Thanks David, Liferay.Session.extend() worked!!!!!!! emoticon But unfortunately I am not able to see the session timeout warning with the timer. Is there any possibility to bring the session timeout warning.
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page.

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
No, if you're auto extending the session it disables the timeout warning altogether. I guess if you never expire you shouldn't need to warn them about it...
thumbnail
Vipin Bardia, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page.

Regular Member Bejegyzések: 162 Csatlakozás dátuma: 2011.02.28. Legújabb bejegyzések
Hi Azhar,

Try below code after your ajax calls if you have them -


Liferay.provide(
         window,
        'sessionKeepAlive',
        function() {
            if (Liferay.Session._stateCheck) {
             window.clearTimeout(Liferay.Session._stateCheck);
              Liferay.Session._stateCheck = null;
            }
            Liferay.Session.init({
              autoExtend: false,
              timeout: Liferay.Session._timeout,
              timeoutWarning:  Liferay.Session._warning
            });
            A.io.request(Liferay.Session._sessionUrls.extend);
        },
        ['aui-io-request', 'aui-io']
    );


Reference : http://htmlr.tumblr.com/post/55563819514/extending-liferay-session-in-the-background
Azhar md, módosítva 9 év-val korábban

RE: Session Expires even i am working on the page.

Junior Member Bejegyzések: 59 Csatlakozás dátuma: 2014.12.01. Legújabb bejegyzések
Hi Vipin,
Thanks for your code but i dont have ajax calls..
If i have ajax calls i will definitely use your code..

Thanks,
Azhar