cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with multiple sessions

stevewickii
Champ in-the-making
Champ in-the-making
I am having trouble with the alfresco session getting closed to early, and subsequent webservice requests throwing exceptions like this "AuthenticationFault: Missing ticket for TICKET_2013a944ec66018941e2be80c8e484074654250d".

I have found that two calls to AuthenticationUtils.startSession with the same username and password return the same Ticket number until AuthenticationUtils.endSession() is invoked.  I have a clustered environment, as I am sure many serious implementers do, and my JSPs from multiple nodes are ending eachother's sessions prematurely because they are each starting their own sessions in parallel and getting the same ticket number.

I am considering NOT calling AuthenticationUtils.endSession() to prevent one JSP from ending another JSP's alfresco session.  Is this a good solution?

Is there an alternative or better way to handle opening and closing sessions?
4 REPLIES 4

stevewickii
Champ in-the-making
Champ in-the-making
After several requests to our website (and several startSession() calls to alfresco) our website stops displaying alfresco content.  The only way to fix the issue is to restart our website (not the alfresco application server).

I have noticed that the alfresco forums are not very active.  Not one of my posts have every been replied to.

stevewickii
Champ in-the-making
Champ in-the-making
I don't believe this problem has anything to do with the Alfresco webservice client API.

The following JSP can be used to show that regardless of the Thread starting the session, Alfresco returns the same ticket number when two sessions start with the same username.  This is the real problem.  Alfresco should not return the same ticket number when startSession() is invoked multiple times for a single username.  Every time startSession() is invoked a new ticket should be created.

Add test.jsp to your web application with the webservice API, and open the test.jsp url in two different browsers.

test.jsp sleeps for 30 seconds to give you time to open test.jsp in another browser, which will start a concurrent session.

Note that the Thread is different but the Ticket is the same for both browsers.

test.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@page import="org.alfresco.webservice.util.AuthenticationUtils"%>
<pre>
Testing Alfresco Connectivity

<%
   AuthenticationUtils.startSession("website", "website");
%>
Started Alfresco Session

Ticket: <%=AuthenticationUtils.getTicket()%>

Thread: <%=Thread.currentThread()%>

Sleeping 30 seconds

<%
   out.flush();
   Thread.currentThread().sleep(30000);
%>
<%
   try
   {
      AuthenticationUtils.endSession();
   }
   catch(Exception e)
   {
      request.setAttribute("endSessionException", e);
   }
%>
<c:choose>
<c:when test="${!empty endSessionException}">Error Ending Alfresco Session
   <table border=1><tr><td>${endSessionException}</td></tr></table>
</c:when>
<c:otherwise>Closed Alfresco Session</c:otherwise>
</c:choose>
</pre>

Invocation 1:

Testing Alfresco Connectivity


Started Alfresco Session

Ticket: TICKET_ea351ff97650d807dd9c93f1428fca28f13d7689

Thread: Thread[http-8080-1,5,main]

Sleeping 30 seconds

Ended Alfresco Session

Invocation 2: (Concurrent to Invocation 1)

Testing Alfresco Connectivity

Started Alfresco Session

Ticket: TICKET_ea351ff97650d807dd9c93f1428fca28f13d7689

Thread: Thread[http-8080-3,5,main]

Sleeping 30 seconds

Error Ending Alfresco Session
   org.alfresco.webservice.util.WebServiceException: Error ending session.

robertoroberto
Champ in-the-making
Champ in-the-making
I also have problems with sessions? Is it an alfresco bug?

stevewickii
Champ in-the-making
Champ in-the-making
This issue has been resolved.  I'm not sure exactly which release the fix was initially deployed to, but I have installed 2.9.0B from the nightly build page, and the problem is solved.  Alfresco always returns a new ticket number when startSession() is invoked.

See http://issues.alfresco.com/browse/AR-1623

Keep in mind that AuthenticationUtils.startSession() caches the ticket number in a threadLocal, and doesn't check for existing sessions, so calling startSession() twice in the same thread will overwrite the ticket, and the second call to endSession() will result in an error because the first ticket is lost.