In a nutshell, what we are seeing is that if we create a new realtime document and immediately share it with another collaborator, and that collaborator loads the realtime document upon seeing it show up in their "Shared with me" folder, then when that collaborator tries to write data to the file, an error occurs, and sometimes the realtime API fails silently.
We have been able to reproduce this both by adding permissions programmatically and by using Google Drive's sharing dialogue. Here are the steps for reproducing this bug.
- Log in to two different Google accounts on separate browsers
- Create a new realtime document in one account
- Copy the URL pointing to the new document
- Share the newly created document with the other account by typing in the email address
- Try to as quickly as possible verify that the new document shows up in the "Shared with me" folder of the other account and paste the copied URL in the other browser to load the document for the other account (I was able to reproduce the issue consistently when doing this in under 30 seconds on my machine, but everything seems to work ok if there is at least a 35 second delay)
- When the document loads for the shared with account, try to write data to the document
- Sometimes the realtime API crashes silently
- If the write to the document uses compound operations, we get the following errors:
- Drive Realtime API Error: invalid_compound_operation: Open compound operation at end of synchronous block - did you forget to call endCompoundOperation()?
- Uncaught DocumentClosedError: Document is closed.
This issue also occurs when sharing an existing file with a new collaborator. When testing on my machine, it appears to be a timing issue, as I can consistently reproduce the error when waiting less than 30 seconds to the load the shared document, and I haven't been able to reproduce the issue when the wait is 35 seconds or more. Another interesting find is that the problem seems to be only with writing data. I am always able to read data from the shared document properly, but if it was loaded in the under 30 seconds scenario, then the first time I try to write data, the issue will occur. What's even more curious is that if the page is refreshed, then it will work properly even if the refresh occurs within 30 seconds of the document being shared.
Thanks.