The problem—how offline submissions can collide

Can you see any reason why the following channel setup will not work?

Suppose you have a channel that lets users look up anagrams for any text string they enter. Being a good channel developer, you do not place these results in the Forms Manager. Instead, you create a cookie with a name="lastsearch" and the value equal to the string that the user is requesting anagrams for. You use this cookie to create a link on the front page that links to their anagram results.

Cookie identifying last search

So far so good.

A while later, you start getting requests from users to keep track of more than one search. Suppose somebody wants to enter several anagram searches between synchronizes, or wants to keep track of a previous anagram search. It would be great if you could keep track of the last three searches. It seems like a good idea, so you go with the following strategy:

  • You keep three cookies: search1, search2, and search3.

  • Every time you get an anagram search request, you take the value of search2 and put it into search3, and take the value of search1 and put it into search2.

  • Then you take the new search and put it into search1.

    In this way, you always have the three most recent searches.

Three cookies identifying last three searches

But something weird happens. Suppose your last three searches consist of Carrot, Banana, and Apple. You then enter three searches for Dates, Eggplant, and Fig and then synchronize. You would expect that your last three searches would then consist of Fig, Eggplant, and Dates. But no—instead, you get Eggplant, Carrot, and Banana. What happened? Why does it seem like two of your three form submissions got dropped?

If the isMulti flag of your submitNoResponse() button is set to true. If it is set to false, then only the most recent form submission will be sent and the other search requests will be dropped. In this case, assume that you remembered to set isMulti to true.

So what else could be wrong? Read on.

The answer is that all three forms are submitted at once when you synchronize. Take a close look at what happens in our anagram channel example.

A form submission searching for anagrams for Dates is sent off to your server with cookie search1=carrot, search2=banana, and search3=apple.

At the same time, form submissions for Eggplant and Fig are also sent off with cookie search1=carrot, search2=banana, and search3=apple.

Multiple multicookie submissions sent to Web server

Suppose the fig submission is finished first. (There are not all that many anagrams for fig, after all.) Your server sends back a response page that sets cookie search1=fig, search2=carrot, and search3=banana.

The Dates submission finishes next. It also sends back a response page that sets cookie search1=dates, search2=carrot, and search3=banana. Remember, the form action has no idea that fig was entered anywhere into the cookie list. It only knows about the cookies that existed at the time the form was submitted. When the M-Business Sync Server receives this, it overwrites the values of the currently existing cookies, essentially sending the fig value into oblivion.

Finally, the Eggplant submission finishes last. It sends back a response page that sets cookie search1=eggplant, search2=carrot, and search3=banana. This the last response page that sets these cookies, so it is only these changes that stick.

Multiple multicookie submissions returned from Web server

After all the form responses are received, M-Business Sync Server then goes about retrieving your front page for your channel. This channel looks at the user's cookies and includes a list to their three previous searches: Eggplant, Carrot, and Banana.