Repository navigation
Retry open file operations when attempting to save source files / source database files - #7823
Conversation
…rce database files. When dropbox or other file syncing solutions are present and attempting to sync source files that are active in the editor, save operations on said files can fail due to the inability to open the file (as it is being read in exclusive mode by the backup software). This change makes it so that now we retry these operations up to a certain amount of seconds, specified by a new user preference save_retry_timeout.
| break; | ||
|
|
||
| // wait a moment before retrying | ||
| boost::this_thread::sleep(milliseconds(500)); |
There was a problem hiding this comment.
Does this actually pause the whole RPC thread? I'm a little concerned that if (a) we auto backup changes every 500ms (the default), and (b) every (other) attempt to write backups pauses the RPC thread for 500+ms as we wait for GDrive (etc) to release the lock, the RPC thread is going to spend a pathologically large time locked.
There was a problem hiding this comment.
It does since it is sleeping. I did my testing with auto save on 500 ms and the performance seemed good. The vast majority of saves are non conflicting - I'd say one in every 15-20 saves produced a stall waiting for the file to become available in my testing. I didn't notice any ill effects from a UX perspective.
This also reduces a bunch of complexity as opposed to retrying the operations in the front end and having to re-queue operations.
There was a problem hiding this comment.
Was your testing on a system with a fast SSD and internet connection? I think that GDrive and friends can have an exclusive lock for much longer on some environments, leading to more save conflicts.
I think we need to give up faster on autosaves. The user generally has another chance to save the file (and will get warned if they try to exit with changes that have never been backed up); it feels wrong that there's a possibility of blocking the entire RPC thread for 15 seconds for an operation the user didn't initiate.
15s isn't unreasonable for a change that must succeed, so I'd suggest a second pref for autosave (auto_save_retry_timeout?) as both a shorter fuse and an escape hatch; it could give up after a second or two, and setting it to 0 would result in a best-effort autosave that just attempts to write the file if it can (the front end could read this value and avoid popping up "file is in use" errors).
There was a problem hiding this comment.
What about not retrying for autosaves period? The whole point of autosaves is that it saves continuously and periodically. Since most operations are successful, we could simply ignore this particular failure for autosaves entirely, with the knowledge that future autosaves will almost assuredly work (since the exclusive file lock will be given up as soon as syncing is done).
We can keep everything as is currently for manual saves, since they are a user initiated action.
|
One worry I have: what if another application locks something in the source database, and for whatever reason refuses to release that lock? It feels like in that case the user could get stuck -- e.g. what if they start mashing the save button (queueing up new save RPC requests) and each of those takes 15 seconds to eventually fail to save and otherwise locks up the IDE for that duration. |
|
@kevinushey I think what we have is reasonable for manual saves because it's a user initiated action, and it's certainly not a common occurrence for these files to be permanently locked by some other application. I do agree that we should only allow one pending save operation in flight at any given time though. Is this something we are already preventing? |
… action. Do not retry writes for autosaves / lints. If not retrying the operation (because of autosave semantics), supress errors indicating that another process is using the file (as it is a transient issue).
…://github.com/rstudio/rstudio into bugfix/google-drive-dropbox-save-enhancements
…ccessfully saved by the source database file properties were not. This would cause annoying prompts asking the user to reload the file as it hasd changed on disk, even though it really had not.
… is a transient exclusive access issue
|
@jmcphers This is ready for another review. These changes continue with the philosophy that autosave transient failures should not produce a user dismissible error - these errors should only show for user initiated actions. Made the following changes:
|
| std::map<std::string, std::string> s_idToPath; | ||
|
|
||
| // cached mapping of document last write times | ||
| std::map<std::string, std::time_t> s_lastWriteTimes; |
There was a problem hiding this comment.
Does this need to be a threadsafe map?
There was a problem hiding this comment.
No - all of these routines execute only on the main thread (thread 0)
Co-authored-by: Jonathan <[email protected]>
…://github.com/rstudio/rstudio into bugfix/google-drive-dropbox-save-enhancements
Fix whitespace issues
|
@jmcphers @kevinushey Updated |
| message); | ||
| // do not show the error if it is a transient autosave related issue - this can occur fairly frequently | ||
| // when attempting to save files that are being backed up by external software | ||
| if (message.contains("The process cannot access the file because it is being used by another process") && suppressFileLockError_) |
There was a problem hiding this comment.
Checking this based on the message rather than an error property or code seems fragile. Would it be feasible for us to send a proper error object (e.g. with an error code) that we could check here or something similar?
There was a problem hiding this comment.
I decided against that because we are using the ProgressIndicator interface here which is tied to error messages and is a very fundamental interface in the code. I didn't think extending this interface was worth it to propagate this one error code here as this would affect a sizable portion of the code base.
…ditors/text/TextEditingTarget.java Co-authored-by: Kevin Ushey <[email protected]>
jmcphers
left a comment
There was a problem hiding this comment.
LGTM, let's definitely add a NEWS entry for this one!
Intent
When dropbox or other file syncing solutions are present and attempting to sync source files that are active in the editor, save operations on said files can fail due to the inability to open the file (as it is being read in exclusive mode by the backup software).
We should attempt to retry these operations so that they do not fail often.
Approach
This change makes it so that now we retry these operations up to a certain amount of seconds, specified by a new user preference
save_retry_timeout, defaulting to 15. This amount of time was chosen for it to be sufficiently long to avoid nearly all exclusive locks held by backup software, while still being short enough to not seem like the operation is stalled.Instead of doing a retry on all file operations via modifying of the
FilePathclass, I scoped this down to only target the helperwriteStringToFile, and its invocations in the source database. This is to reduce impact and risk of inadvertently slowing down some other processes in other parts of the code base that might not expect it.Closes #7131
QA Notes
See repro steps in #7131. The user pref
save_retry_timeoutcan be lowered to increase the likelihood of reproducing the original issue.