Solved

Concurrent HTTP Session is returning wrong user

Posted on 2013-05-14
3
408 Views
Last Modified: 2013-05-26
I am experiencing a quite weird problem. When two users are logging at the exact same time, one of them is detected as the other.


        locale = new Locale(getLocale(request).getLanguage(), getLocale(request).getCountry());
        
	
        strRemoteUser = WebTools.getUserIdWithoutDomainName(request.getRemoteUser()).toUpperCase();
    	
    	logger.info("[MYAPP] User " + strRemoteUser + " is logging in");

    	logger.info("[MYAPP] Creating session for : " + strRemoteUser);
    	
        HttpSession session = request.getSession(false);

        if (session != null) {
		
            session.invalidate();
            session = request.getSession();
        }       

        logger.info("[MYAPP] User in session is : " + strRemoteUser);    	      

Open in new window

         
What I get is the following. Let's assume that two users (USR001 and USR002) are logging to the application at the same exact time. They are located in a different location.

Logs:

		2013-05-14 08:19:38,550 INFO  [com.myapp.action.common.LoginAction] [MYAPP] User USR001 is logging in
	2013-05-14 08:19:38,551 INFO  [com.myapp.action.common.LoginAction] [MYAPP] Creating session for : USR001
	2013-05-14 08:19:38,760 INFO  [com.myapp.action.common.LoginAction] [MYAPP] User USR002 is logging in
	2013-05-14 08:19:38,761 INFO  [com.myapp.action.common.LoginAction] [MYAPP] Creating session for : USR002
	2013-05-14 08:19:38,834 INFO  [com.myapp.action.common.LoginAction] [MYAPP] User in session is : USR002
	2013-05-14 08:19:39,104 INFO  [com.myapp.action.common.LoginAction] [MYAPP] User in session is : USR002
	2013-05-14 08:19:39,425 INFO  [com.myapp.action.common.LoginAction] [MYAPP] Auto Added User USR002
	2013-05-14 08:19:39,550 INFO  [com.myapp.action.common.LoginAction] [MYAPP] Setting user in session: USR002 (673)

Open in new window


As you can see, USR002 "wins" the concurrent session creation as USR001 is now recognized as USR002. If USR001 logs out and then log back in, it works properly.

Any thoughts/advice?

Thank you very much for help.

Specs:

* jBoss 4.2.3GA
* PostgreSQL 9.0.3
* Struts 1.3.5
* EJB3
0
Comment
Question by:SolutionsTI
  • 2
3 Comments
 
LVL 16

Expert Comment

by:krakatoa
ID: 39165795
And is it the same weird problem that you posted over on Stackoverflow?
0
 

Accepted Solution

by:
SolutionsTI earned 0 total points
ID: 39184035
Yes. Same problem.

The problem was in fact that the strRemoteUser was defined as a Class Variable for my LoginAction Struts action class.

This action is used by any user attempting to log in to the system. One gentleman on stackoverflow told my that Class Variables are common concurrent problem so I gave it a try.

Instead of a class variable I kept the strRemoteUser as a variable, and then pass it to all methods where I needed it.

It worked! The day after I had more than 80 people login in at the same time. The problem is now solved permanently.

Thank you
0
 

Author Closing Comment

by:SolutionsTI
ID: 39197417
I have found the solution on another site. The solution has been shared on Experts-Exchange.

Thank you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now