EllisLab/CodeIgniter — pull request #1283 by Areson (2012-04-23 23:52:17+00:00)
Title: Enable simultaneous AJAX requests to work with sessions

This is in response to issue #154.

This update allows sessions to work gracefully with fast/simultaneous requests without needing to simply ignore updating the session. Users are allowed to have more than one valid session id at any given time, but only one is considered to be "active." The active session id is allowed to be updated (e.g. generate a new session id), but the original session id is left intact, marked as "inactive." Inactive sessions exist solely to make sure the requests that are created near the time a session is regenerated behave properly.

To facilitate this change an additional expiration time has been added, resulting in three "timeouts" for sessions:
* Session Expiration: The point at which _any_ request is destroyed
* Time to Update: The point at which the active session id is regenerated
* Multisession Expiration: The point which an inactive session is no longer valid

Here is an example of a session lifetime:
* User interacts with the site for the first time, creating a new and active session, Session 1
* After the Time to Update has passed, Session 1 is "updated." This process results in a new id being generated and associated with the new active session, Session 2. Session 1 is marked as inactive.
* An AJAX request comes in with Session 1. Since it is marked as inactive, no update occurs, but the AJAX session completes because it has a valid session.
* The multisession expiration passes
* At this point, one of two final outcomes can happen:
* Another AJAX request comes in with Session 1. Since the multisession expiration has passed, the session is destroyed and the AJAX request fails due to not having a valid session. (This is very unlikely)
* The session expiration passes for Session 1. The session will be destroyed during the course of the normal cleanup processes for sessions. Any request coming in for that session id will fail.