fs.Dir.deleteTree: Add configurable max_retries to avoid infinite loops #15467
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, it was possible for deleteTree to get into a state where it would continually retry deleting the same directory over and over infinitely, since it would think all of the children were successfully deleted but when deleting the directory it would hit
error.DirNotEmpty. Now, there is a (user-configurable) limit to the number of times it will retry deleting directories, and returnerror.TooManyRetriesif the limit is exceeded.Closes #15465, possibly related to #14948
Follow up to #13073 (comment) (cc @matu3ba)
Notes:
usizeformax_retriesis definitely overkill, but using a smaller type didn't affect@sizeOf(StackItem)indeleteTreeso I just stuck withusizeoptionsparameter allowed for makingkind_hintconfigurable which can be used to save a syscall if you know what the type ofsub_pathis (it's defaulted to.Filesince that's how it's always worked, but maybe.Directorywould be a better default? Or maybe callsites should just pass.Directorymore often?)DeleteFilebehavior added in windows: use NtSetInformationFile in DeleteFile. #15316 (DELETE_PENDINGtreated as success), relevant issue: unhandled NTSTATUS: DELETE_PENDING in std.os.windows.DeleteFile #6452in
TmpDir.cleanup