I am sure that we all worked or know about web applications (especially in the enterprise) that are closely related to the server session. In these cases, it is possible that the session will be corrupted if multiple browser sessions are open and the same server session cookie is used. We looked at all the options and found a better way forward to discourage the use of multiple browser sessions that share the server session cookie.
This is really a problem when the user runs New Window - Ctrl+N in IE or the equivalent of the "duplicate tab" in other browsers. In essence, we get two active browser sessions that use the same cookies.
So, to prevent this (as this is likely to be unintentional), I intended to introduce some kind of warning system to prevent this behavior. Now our code does a lot of concurrency checks to ensure data integrity, but there may still be problems with data corruption.
My solution, finding that the general answer was “impossible,” was to rely on AJAX to send pings and measure the time between them. So, we have a general rule: we are “ping” with a certain interval, and if the delta between the last ping in the current ping is less than the ping duration, we know that we have several active browser sessions on the same server session.
So where Pf is the ping frequency; Pc - current ping; and Pl is the last ping, then we have an error when Pf > (Pc - Pl) .
p1 p2 p3 p4
TAB1 0 ----- | ----- | ----- | ----- | ---...
:::
: p1: p2: p3 p4
TAB2 0 ----- | ----- | ----- | ----- | ---...
^ ^ ^ ^ ^ ^ ^ ^ ^
Deltas
---- + --- + ------------
TAB | P | Delta (Pc - Pl)
---- + --- + ------------
1 | 1 | 5
1 | 2 | 5
2 | 1 | 2.5 -Error
1 | 3 | 2.5 -Error
2 | 2 | 2.5 -Error
Now, if there is network congestion or other factors, then the delta will be more than the frequency, excluding false alarms.
We have a problem if two tabs are open at the same moment. But since the ping frequency is the frequency at which requests are executed, and not the guaranteed elapsed time, we can assume that soon both browser sessions will begin to go out of sync.
In the example, I have a ping frequency set every 5 seconds. If there are 100 concurrent users, we look through ~ 20 requests / second for the ping servlet / HttpModule. To minimize unnecessary network traffic, I thought the ping frequency would decay over time until a maximum of 20 peaks per second was reached. This will be ~ 5 requests / second with 100 concurrent users. However, this is a compromise, as this will cause a delay in detection. However, as soon as detection occurs, the frequency is reset to 5 pins / second until resolution. (These numbers are given as an example: they will vary depending on the environment)
To minimize concurrency and scalability issues, the last ping timestamp for the session should be stored in the session itself. This will allow any distributed session technology to maintain session availability through the JVM or application domains without our ping service to be aware of.
I am trying to determine if this is the right approach if I am in the world of pain. Any experience related to the problem will be helpful.
EDIT: I know this sounds like tape help, but that means it will be a long lasting measure until we can rip off the violating library.