Skip to content

Commit

Permalink
Merge pull request #51244 from sharwell/failed-save
Browse files Browse the repository at this point in the history
Handle failed SaveAsync operations
  • Loading branch information
sharwell authored Feb 19, 2021
2 parents d402ca8 + 2455535 commit 7b604ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)

// MemoryMapped files which are used by the TemporaryStorageService are present in .NET Framework (including Mono)
// and .NET Core Windows. For non-Windows .NET Core scenarios, we can return the TrivialTemporaryStorageService
// until https://github.com/dotnet/roslyn/issues/42178 is fixed.
// until https://github.com/dotnet/runtime/issues/30878 is fixed.
return PlatformInformation.IsWindows || PlatformInformation.IsRunningOnMono
? (ITemporaryStorageService)new TemporaryStorageService(textFactory)
: TrivialTemporaryStorageService.Instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ private void ResetRecoverySource(Task saveTask, T instance)
{
using (Gate.DisposableWait(CancellationToken.None))
{
_recoverySource = new AsyncLazy<T>(RecoverAsync, Recover, cacheResult: false);
// Only assume the instance is saved if the saveTask completed successfully. If the save did not
// complete, we can still rely on a constant value source to provide the instance.
_recoverySource = saveTask.Status == TaskStatus.RanToCompletion
? new AsyncLazy<T>(RecoverAsync, Recover, cacheResult: false)
: new ConstantValueSource<T>(instance);

// Need to keep instance alive until recovery source is updated.
GC.KeepAlive(instance);
Expand Down

0 comments on commit 7b604ab

Please sign in to comment.