Skip to content

Fix HTTP cache checksum mismatch for resources#4886

Open
Zephkek wants to merge 1 commit intomultitheftauto:masterfrom
Zephkek:fix-http-cache-file-mismatch
Open

Fix HTTP cache checksum mismatch for resources#4886
Zephkek wants to merge 1 commit intomultitheftauto:masterfrom
Zephkek:fix-http-cache-file-mismatch

Conversation

@Zephkek
Copy link
Copy Markdown
Contributor

@Zephkek Zephkek commented May 4, 2026

Summary

Fix HTTP resource file mismatches when large client files are updated.

Motivation

Resolves #4161. The server could advertise a checksum from the source file, then serve different bytes because the HTTP cache was copied in a separate pass. Large files made that race much easier to hit.

Test plan

  • Verify stale HTTP cache files are now copied to a temp file, checksummed from the copied bytes, then published after validation.

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

@Zephkek Zephkek force-pushed the fix-http-cache-file-mismatch branch from bc5bdaf to 90a1d18 Compare May 4, 2026 09:56
@qaisjp qaisjp requested a review from Copilot May 10, 2026 04:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a race where the server could advertise a checksum from the source resource file but end up serving different bytes from the HTTP cache, most visible with very large client files (issue #4161 / diagnostic #1013).

Changes:

  • Introduces a temp-file copy + checksum flow so the checksum is derived from the exact bytes that will be served from the HTTP cache.
  • Publishes the refreshed HTTP cache file via an atomic-ish replace step (rename/MoveFileExW) after validation and blocklist checks.
  • Defers updating CResourceFile’s last checksum/size hint until after HTTP cache refresh logic completes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +97 to +104
if (MoveFileExW(FromUTF8(strTempPath), FromUTF8(strCachedFilePath), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) == 0)
{
if (pOutErrorCode)
*pOutErrorCode = GetLastError();
return false;
}

return true;
Comment on lines 634 to 642
auto checksumOrError = CChecksum::GenerateChecksumFromFile(strPath);
if (std::holds_alternative<std::string>(checksumOrError))
{
return SString(std::get<std::string>(checksumOrError));
}

pResourceFile->SetLastChecksum(std::get<CChecksum>(checksumOrError));
pResourceFile->SetLastFileSizeHint(static_cast<uint>(FileSize(strPath)));
CChecksum checksum = std::get<CChecksum>(checksumOrError);
uint64 fileSize = FileSize(strPath);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#1013 HTTP server file mismatch

2 participants