Skip to content

Conversation

Dentomologist
Copy link
Contributor

On Windows, when the Rename function fails to replace an existing file
it will now retry the operation multiple times with increasingly long
delays between attempts. This fixes transient rename failures.

I've been getting sporadic yet annoyingly frequent errors saying:
'IOS_FS: Failed to rename temporary FST file'
These typically appear on startup but I've also gotten them randomly.

Investigation shows this happens when the Windows ReplaceFile function
returns the error ERROR_UNABLE_TO_REMOVE_REPLACED. That happens in the
context of using ReplaceFile to perform an atomic file overwrite, which
is required when saving updates to a file to avoid corruption. The
error mainly happens with the /Wii/fst.bin file but I've seen it
happen with multiple other files as well.

I haven't been able to definitively pin down why the error occurs,
though online discussions suggest antivirus scanning may be a major
culprit. That said, I've excluded the Dolphin folder from Windows
Defender scans to no avail and don't have any other antivirus running,
so this is likely to be a problem others are experiencing as well.

The number and duration of retry delays is arbitrary but I feel like a
combined second or so in the worst case is an acceptable tradeoff for
the reduction (actually elimination in my experience) of those errors.
This is even more true when you consider the time it takes to read and
dismiss the error dialogs.

@AdmiralCurtiss
Copy link
Contributor

see also #9023

@AdmiralCurtiss
Copy link
Contributor

That said, retrying a rename on failure is not the worst idea in the world, though 8 attempts with a total of ~1 second delay seems pretty excessive. Imagine if you had a case where it legitimately can't rename files due to eg. missing rights and something attempted to rename even just 10 files in succession.

@Dentomologist
Copy link
Contributor Author

I'm totally open to adjusting the number and timing of delays. The current set were chosen with an eye to minimizing the likelihood of a transient error still popping up a dialog, but your point about multiple files is well taken.

I'll read up on #9023 but I notice it's from back in August. If finishing it would take a while we could use this PR (with adjusted delays; maybe 5/10/25 milliseconds) as a stopgap until #9023 is done.

@Dentomologist Dentomologist force-pushed the fix-fst-error branch 2 times, most recently from a896ae7 to c3e9c8e Compare November 24, 2020 17:27
const auto attempt_func = [&, source_ptr, destination_ptr]() {
if (ReplaceFile(destination_ptr, source_ptr, nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS, nullptr,
nullptr))
{
Copy link
Member

Choose a reason for hiding this comment

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

Same regarding the braces here -- this would be more readable if it were more compact.

}
// Might have failed because the destination doesn't exist.
if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
Copy link
Member

Choose a reason for hiding this comment

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

braces

On Windows, when the Rename function fails to replace an existing file
it will now retry the operation multiple times with increasingly long
delays between attempts.  This fixes transient rename failures.

I've been getting sporadic yet annoyingly frequent errors saying:
'IOS_FS: Failed to rename temporary FST file'
These typically appear on startup but I've also gotten them randomly.

Investigation shows this happens when the Windows ReplaceFile function
returns the error ERROR_UNABLE_TO_REMOVE_REPLACED.  That happens in the
context of using ReplaceFile to perform an atomic file overwrite, which
is required when saving updates to a file to avoid corruption.  The
error mainly happens with the /Wii/fst.bin file but I've seen it
happen with multiple other files as well.

I haven't been able to definitively pin down why the error occurs,
though online discussions suggest antivirus scanning may be a major
culprit.  That said, I've excluded the Dolphin folder from Windows
Defender scans to no avail and don't have any other antivirus running,
so this is likely to be a problem others are experiencing as well.

The number and duration of retry delays is arbitrary but I feel like a
combined second or so in the worst case is an acceptable tradeoff for
the reduction (actually elimination in my experience) of those errors.
This is even more true when you consider the time it takes to read and
dismiss the error dialogs.
@leoetlino leoetlino merged commit 4c9ffb5 into dolphin-emu:master Nov 26, 2020
@dolphin-emu-bot

This comment has been minimized.

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

Successfully merging this pull request may close these issues.

5 participants