in reply to Concurrent requests on the same CGI::Session

I would consider submitting a patch.   The scenario that you describe is unfortunately a pretty-common “race condition.”

Otherwise, build a descendant class... and please then consider contributing it to CPAN, where I am sure it will be very well received.

Many CGI session handlers are not-very-well architected (IMHO...) for AJAX needs.   (And I do mean that in a very constructive and positive way.)   Even though the design principles needed for suitable session-stores are straightforward enough, I am really not aware of any packages that do AJAX well... for the very reasons you describe.   (And if this thread could now expand to include a list of a few that notably are, that would be a Very Good Thing.™)

Replies are listed 'Best First'.
Re^2: Concurrent requests on the same CGI::Session
by Anonymous Monk on Jan 17, 2011 at 14:27 UTC
    Many CGI session handlers are not-very-well architected (IMHO...) for AJAX needs. (And I do mean that in a very constructive and positive way.)

    For that to be constructive it has to be more specific

      Sure... no problem.

      The problem is twofold:   (a) that Session handlers normally replace the entire set of variables; and (b) that there is no “change counter.”   (Usually, database transactions are used, but that is not sufficient.)

      Therefore, when two or more simultaneous requests start, both of them get the same set of initial-data, and the last one to complete overwrites the entire set of changes previously posted by all of the requests preceding it (in completion-time).   Precisely as the OP observed.

      A more-sophisticated approach is needed, such as... partitioning the data, providing change-counters that are incremented with each update (of a given partition) and so on.   I am very interested to find session-support modules that can do these things automagically.   (Although such a thing can be written... “laziness is a virtue among programmers, you know.”)

        A more-sophisticated approach is needed, such as... partitioning the data, providing change-counters that are incremented with each update (of a given partition) and so on.

        Nowhere near detailed enough, though it does remind me of CHI -- either way, the app developer will always have to write his own state logic (think of TCP session and out of order packets, etc)

Re^2: Concurrent requests on the same CGI::Session
by webdeveloper (Novice) on Jan 17, 2011 at 15:36 UTC

    Thanks - it's very useful at least to hear that this is a 'known issue'.

    "Even though the design principles needed for (AJAX) suitable session-stores are straightforward enough..."

    I just wanted to ask if you had any specific references or resources in mind that might list these, as it would be good to be aware of all the potential issues surrounding this topic when considering an alternative way to approach it. Thanks!