[GLASSFISH-17118] Server-Shutdown: keepSessions=true causes HTTP sessions to expire before writing to SESSIONS.ser Created: 27/Jul/11  Updated: 17/Oct/11  Resolved: 29/Jul/11

Status: Resolved
Project: glassfish
Component/s: web_container
Affects Version/s: 3.1
Fix Version/s: 3.1.2_b01

Type: Bug Priority: Critical
Reporter: ahummel Assignee: Shing Wai Chan
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

persistence-type: memory (default)


During server shutdown, the com.sun.enterprise.web.WebContainer.unloadWebModule and com.sun.enterprise.web.WebModule.saveSessions methods are invoked. If keepSessions=true, this causes a org.apache.catalina.session.StandardManager.writeSessions(OutputStream) call which expires all current sessions. As a consequence, the sessions cannot be passivated to the SESSIONS.ser file, thus, HTTP session do not survive a server restart - which is wrong IMHO.

If keepSessions=false, the sessions survive a server restart.

Comment by Shing Wai Chan [ 27/Jul/11 ]

The above code analyze is not correct.
The HTTP sessions are writing to a file before calling expire.

I have verified that the unit test sessionPreserveAcrossRedeploy is running fine.

Comment by ahummel [ 28/Jul/11 ]

I do not agree. Preserving across redeploy may work - but preserving across restart does not (I did the above code analysis because my HTTP sessions did not survive a server restart). Here is the output of the log:

INFO: Server shutdown initiated
INFO: ShoppingCart: pre-passivate com.foo._ShoppingCart_Serializable@7f4425
FEIN: Unloading 1 sessions
FEIN: Expiring 1 persisted sessions
FEIN: Stopping filters
FEIN: Stopping
FEIN: Unloading persisted sessions
FEIN: PWC2771: Saving persisted sessions to shoppingcart_SESSIONS.ser
FEIN: Unloading 0 sessions
FEIN: Unloading complete

The "Unloading 1 sessions" happens when the sessions are written to the ByteArrayOutputStream for preserving across redeploy (written into properties). After writing to the ByteArrayOutputStream the sessions expire ("Expiring 1 persisted sessions").

The "Unloading 0 session" happens when the server is stopping and the sessions should be written to the shoppingcart_SESSIONS.ser file. But nothing - except the number 0 - is written to the file.

Server start does not read anything:

FEIN: Start: Loading persisted sessions
FEIN: PWC2766: Loading persisted sessions from shoppingcart_SESSIONS.ser
FEIN: Loading 0 persisted sessions
FEIN: Finish: Loading persisted sessions

Comment by Shing Wai Chan [ 28/Jul/11 ]

keepSessions is for preserving sessions across redeployment.
One can find more details in http://weblogs.java.net/blog/swchan2/archive/2011/03/09/keepstate-keepsessions-keep-state-save-sessions-enabled-glassfish-31

If you want to keep session across restarts, then you may like to have a sun-web.xml as follows:

        <property name="sessionFilename" value="mysessionfile" />
Comment by ahummel [ 29/Jul/11 ]

Yes, I know that keepSessions is for preserving sessions across redeployment.

What I mean is that whenever the keepSessions feature is activated this has a negative side effect because it prevents sessions to survive a server restart. Or in other words: I assumed that session-survival for server restart is independent of the keepSessions-feature. But when I activate the keepSessions feature my sessions do not survive a server restart anymore. (please see the above log extract which shows that keepSession=true first unloads and expires my sessions... and when it tries to preserve the sessions for a server restart, no sessions exist anymore.... the first unloading/expiring step does not happen when keepSessions is not active and the sessions are correctly preserved for a server restart)

Comment by Shing Wai Chan [ 29/Jul/11 ]

keepSessions and preserving sessions across restart are two different features.

Are you using 3.1 or 3.1.1?
In 3.1.1, persevering sessions across restart is turned off by default.

Comment by Shing Wai Chan [ 29/Jul/11 ]

I find that the issue.
If keepSessions and preserving session on restart are both turned on, then StandardManager#writeSessions are invoked twice with doExpire true and false respectively.

Comment by Shing Wai Chan [ 29/Jul/11 ]

Sending web-core/src/main/java/org/apache/catalina/session/StandardManager.java
Sending web-glue/src/main/java/com/sun/enterprise/web/WebModule.java
Transmitting file data ..
Committed revision 48467.

Comment by Shing Wai Chan [ 04/Aug/11 ]

Port the fix to 3.1.2

Sending web/web-core/src/main/java/org/apache/catalina/session/StandardManager.java
Sending web/web-glue/src/main/java/com/sun/enterprise/web/WebModule.java
Transmitting file data ..
Committed revision 48574.

Generated at Sat Jul 04 21:57:32 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.