glassfish
  1. glassfish
  2. GLASSFISH-17118

Server-Shutdown: keepSessions=true causes HTTP sessions to expire before writing to SESSIONS.ser

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: 3.1.2_b01
    • Component/s: web_container
    • Labels:
      None
    • Environment:

      persistence-type: memory (default)

      Description

      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.

        Activity

        Hide
        Shing Wai Chan added a comment -

        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.

        Show
        Shing Wai Chan added a comment - 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.
        Hide
        ahummel added a comment -

        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
        [snipped]
        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

        Show
        ahummel added a comment - 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 [snipped] 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
        Hide
        Shing Wai Chan added a comment -

        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:

        <sun-web-app>
          <session-config>
            <session-manager>
              <manager-properties>
                <property name="sessionFilename" value="mysessionfile" />
              </manager-properties>
            </session-manager>
          </session-config>
        </sun-web-app>
        
        Show
        Shing Wai Chan added a comment - 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: <sun-web-app> <session-config> <session-manager> <manager-properties> <property name= "sessionFilename" value= "mysessionfile" /> </manager-properties> </session-manager> </session-config> </sun-web-app>
        Hide
        ahummel added a comment -

        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)

        Show
        ahummel added a comment - 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)
        Hide
        Shing Wai Chan added a comment -

        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.

        Show
        Shing Wai Chan added a comment - 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.
        Hide
        Shing Wai Chan added a comment -

        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.

        Show
        Shing Wai Chan added a comment - 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.
        Hide
        Shing Wai Chan added a comment -

        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.

        Show
        Shing Wai Chan added a comment - 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.
        Hide
        Shing Wai Chan added a comment -

        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.

        Show
        Shing Wai Chan added a comment - 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.

          People

          • Assignee:
            Shing Wai Chan
            Reporter:
            ahummel
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: