When my Realtime API based app is experiencing heavy usage new users have a hard time loading the data model. In this scenario users see the follow error in their console:
Uncaught java.lang.IllegalStateException: Initial revision has already been set.
Ry index.html:705
Vx index.html:134
T index.html:900
bb index.html:399
Pf index.html:462
Sf index.html:982
(anonymous function) index.html:490
Kh api:152
W.Ga api:151
...
Where the stack trace represents code injected by the Realtime API.
When the existing users stop interacting with the data for a period new users are able to load the data model as expected.
I have passed an error function to the load call--as it is done in rtclient.RealtimeLoader.prototype.load
in the realtime-client-utils.js
sample code Google provides as part of the Quickstart documentation. My error function is called for some errors; however, it is not called for the error case this question is concerned with.
What should my data model loading code look like to allow users to be able to use my app under all usage conditions?
Mayra suggested this error should only occur when two users try to initialize the model at the same time; however, this does not match with the behavior I see. To aid in getting an answer I have created a jsFiddle example that can reproduce the problem. The example is based off of the code provided in the Quickstart page with only minor changes.
To reproduce the problem open the jsFiddle example in three browser tabs and...
Switch File
button and paste the file id into the prompt box.Create Data
button in both tabs to put the app under some load. (Some details are logged in the console)The interesting details are that the initialization function is not getting called at all and only one user is trying to initialize the data model in this scenario.
This should only occur when two users try to initialize a new document at the same time. In order to guarantee that the document is initialized exactly once, if a second user attempts to reinitialize an already-initialized document, you would get this exception.
The correct thing to do is to just reload the document when you see this exception. However, its surprising that you are seeing this so often.
Are you doing a lot of work in your initialize function? Do you have some setup where a lot of users try to load the same new document at the same time?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With