Solved

Concurrent HTTP Session is returning wrong user

Posted on 2013-05-14
3
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example for saving data 19 73
What's wrong with this code? 4 34
intellij error 2 27
hashmap order 17 40
In this post we will learn different types of Android Layout and some basics of an Android App.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

735 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