J2EE – Session swap

Application server – JBoss AS 7.1.1
JDK6
J2EE 1.3

My web application is more than 10 years old and facing this session swap problem in my portal. Noticed
that swap happens mostly when many concurrent users accessing the portal and underlying windows server is busy
(more than 90% CPU usage)

To analyse this issue, I logged customer data (customer id, ip address, jsession id) to a table and found
that customer having unique jsession id initially has his data and all of a sudden for the same jsession id and
ip address receiving different customer data.

customer1  123.123.12.123   jsessionid123    11:10:02
customer2  123.123.12.123   jsessionid123    11:10:04

ip address (123.123.12.123) having jsession id (jsessionid123) somehow gets customer2 data

Any order placed by customer1 in ip – 123.123.12.123 gets created for customer2, I confirmed this by
calling customer2 and they confirmed that they didn’t place the order. customer1 won’t realise he placed
order for customer2 – all the data gets changed, like basket items, customer object, products etc.

Now I need to find a fix for this, but first I need to know which part of my code is creating this problem.

Do I have to use a stress test software? or any better mechanism to find out the problematic code?

Look whether you are storing data in singletons (eg servlet) or in pooled objects. To be clear, variables inside function are ok, only something in servlet itself is problem.
In comment you say you choose action, if you choose existing instance, then you should not store session wide data in it.

Once I seen (ehm, caused) similar problem caused by incorrectly using phase listeners (in JSF) where we created listener for each request (which led to similar sindroms + after while it was extremely slow (executing listeners extremely many times). I quess that this is not your problem.

1

I’ve experienced something like this before. In my experience, the Action class that’s supposed to receive data from the JSP is instantiated as a singleton, so when there are many concurrent users, the singleton class gets ‘reused’ which caused the apparent ‘session-swapping’.
So check the whatever class is receiving your user inputs (for example, Action class in struts framework), and make sure that its not singleton.

2

I found a fix for this problem. In my case, the in-house framework got the below code which caused the problem,

        ...
        req.setAttribute(key, value); /* This code gets executed for both REQUEST & SESSION */
        if (scope == Sp.SESSION) {
            req.getSession().setAttribute(key, value);
            ...

I noticed somehow the code maps session objects to incorrect jsessionid, so I tried the below code,

        ...
        if (scope == Sp.REQUEST) { /* Added this check */
            req.setAttribute(key, value);
        }
        if (scope == Sp.SESSION) {
            req.getSession().setAttribute(key, value);
            ...

It’s nearly a year after this fix, and the swap didn’t happen at all. So I’m confident this code fix solved the swap problem.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật