Skip to content

Commit

Permalink
Try invalidating NFS cache by doing a write
Browse files Browse the repository at this point in the history
Instead of calling `sync`, which doesn't seem to be invalidating the
correct NFS dir cache, we'll try to force the NFS cache to be sent to
the server by writing a file into the .hg folder, then trying to do an
`ls` on the other side.
  • Loading branch information
rmunn committed May 28, 2024
1 parent a620a93 commit 9c25907
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions backend/LexBoxApi/Services/HgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ await Task.Run(() =>
{
InitRepoAt(new DirectoryInfo(PrefixRepoFilePath(code)));
});
await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows
// TODO 789: In theory this shouldn't need an invalidate call? Try with and without
await InvalidateDirCache(code);
// await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows
await WaitForRepoEmptyState(code, RepoEmptyState.Empty);
}

Expand Down Expand Up @@ -108,8 +110,8 @@ public async Task ResetRepo(string code)
await SoftDeleteRepo(code, $"{FileUtils.ToTimestamp(DateTimeOffset.UtcNow)}__reset");
//we must init the repo as uploading a zip is optional
tmpRepo.MoveTo(PrefixRepoFilePath(code));
await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows
// await InvalidateDirCache(code); // TODO 789: Sometimes NFS hasn't finished the MoveTo above! So we need to find a way to wait until InvalidateDirCache sees an *empty* repo...
// await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows
await InvalidateDirCache(code); // TODO 789: Does this work now?
await WaitForRepoEmptyState(code, RepoEmptyState.Empty);
}

Expand Down Expand Up @@ -144,8 +146,8 @@ await Task.Run(() =>
// Now we're ready to move the new repo into place, replacing the old one
await DeleteRepo(code);
tempRepo.MoveTo(PrefixRepoFilePath(code));
// await InvalidateDirCache(code);
await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows
await InvalidateDirCache(code);
// await Process.Start("sync").WaitForExitAsync(); // TODO: Put behind an OS check so we don't break Windows
await WaitForRepoEmptyState(code, RepoEmptyState.NonEmpty); // TODO: Either catch the case where someone uploaded a .zip of an empty .hg repo, or set a timeout in WaitForRepoEmptyState
}

Expand Down Expand Up @@ -274,7 +276,12 @@ public async Task<HttpContent> ExecuteHgRecover(string code, CancellationToken t

public Task<HttpContent> InvalidateDirCache(string code)
{
return ExecuteHgCommandServerCommand(code, "invalidatedircache", default);
// TODO: Ensure we don't accidentally re-create a repo we tried to delete by doing the line below
// I.e., check if PrefixRepoFilePath(code) exists and if it doesn't, create and delete it alone
var d = Directory.CreateDirectory(Path.Join(PrefixRepoFilePath(code), ".tmp-invalidate")); // Try to force NFS to invalidate

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.
var result = ExecuteHgCommandServerCommand(code, "invalidatedircache", default);
try { if (d.Exists) d.Delete(); } catch(Exception) {} // Clean up no matter what
return result;
}

public async Task<string> GetTipHash(string code)
Expand Down

0 comments on commit 9c25907

Please sign in to comment.