Solved

Concurrent HTTP Session is returning wrong user

Posted on 2013-05-14
3
420 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

729 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