3

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...

  • Authorize if you have not done so yet.
  • Copy the file id from the first tab.
  • In the second tab press the Switch File button and paste the file id into the prompt box.
  • Modify the text in the text box and verify the changes are propagated between tabs...If so the Realtime API is working as expected.
  • Now press the Create Data button in both tabs to put the app under some load. (Some details are logged in the console)
  • To see the problem in the third tab open the console to view log messages.
  • Also in the third tab switch the file id to the same id used by the other two tabs. Observe that the third tab is unable to collaborate on the specified file id and sees the error I am observing.

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.

Community
  • 1
  • 1
JesseHenn
  • 73
  • 6

2 Answers2

2

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?

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
1

I don't have enough reputation to leave a comment - but we can repeat this problem as well, and it's not just at initialization time. It's completely reproducable, and happens when one user tries to open a file (not re-init it, just open) while another one is editing it.Here's a screenshot of the JS console

The problem with catching this is it seems to happen in a separate call stack, so try/catch around gapi.drive.realtime.load does not help with catching it at all. Using the error handler argument in load also does not work, this error seems to go unnoticed

Gojko Adzic
  • 1,241
  • 10
  • 9