Skip to content

Conversation

jonathanpeppers
Copy link
Member

Context: https://build.azdo.io/3575078
Context: https://build.azdo.io/3574952

Our CI builds have been hitting random failures such as:

(_UpdateAndroidResgen target) ->
error XARDF7024: System.IO.IOException: The directory is not empty.
error XARDF7024:
error XARDF7024:    at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data)
error XARDF7024:    at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
error XARDF7024:    at Xamarin.Android.Tasks.RemoveDirFixed.RunTask()

Or in another target:

(_CreateBaseApk target) ->
error XARDF7024: System.IO.IOException: The directory is not empty.
error XARDF7024:
error XARDF7024:    at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data)
error XARDF7024:    at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
error XARDF7024:    at Xamarin.Android.Tasks.RemoveDirFixed.RunTask()

In both of these places, we have the pattern:

<CreateTemporaryDirectory>
  <Output TaskParameter="TemporaryDirectory" PropertyName="AaptTemporaryDirectory" />
</CreateTemporaryDirectory>
<!-- Then later on -->
<RemoveDirFixed Directories="$(AaptTemporaryDirectory)" />

The temporary directory is created in C# via:

TemporaryDirectory = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ());
Directory.CreateDirectory (TemporaryDirectory);

I think a solution here is to make the <RemoveDirFixed/> call set to
ContinueOnError="WarnAndContinue". I don't think we need to fail
the overall build in these scenarios.

The user is going to have leftover files in %TEMP%, and I don't
think there is much we can do. Changing this from a build error to a
warning is a general improvement if we are unable to delete the
directory. The error code will also be preserved.

I don't know if this will help our users at all, but should help our CI.

… dirs

Context: https://build.azdo.io/3575078
Context: https://build.azdo.io/3574952

Our CI builds have been hitting random failures such as:

    (_UpdateAndroidResgen target) ->
    error XARDF7024: System.IO.IOException: The directory is not empty.
    error XARDF7024:
    error XARDF7024:    at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data)
    error XARDF7024:    at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
    error XARDF7024:    at Xamarin.Android.Tasks.RemoveDirFixed.RunTask()

Or in another target:

    (_CreateBaseApk target) ->
    error XARDF7024: System.IO.IOException: The directory is not empty.
    error XARDF7024:
    error XARDF7024:    at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data)
    error XARDF7024:    at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
    error XARDF7024:    at Xamarin.Android.Tasks.RemoveDirFixed.RunTask()

In both of these places, we have the pattern:

    <CreateTemporaryDirectory>
      <Output TaskParameter="TemporaryDirectory" PropertyName="AaptTemporaryDirectory" />
    </CreateTemporaryDirectory>
    <!-- Then later on -->
    <RemoveDirFixed Directories="$(AaptTemporaryDirectory)" />

The temporary directory is created in C# via:

    TemporaryDirectory = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ());
    Directory.CreateDirectory (TemporaryDirectory);

I think a solution here is to make the `<RemoveDirFixed/>` call set to
`ContinueOnError="WarnAndContinue"`. I don't think we need to *fail*
the overall build in these scenarios.

The user is going to have leftover files in `%TEMP%`, and I don't
think there is much we can do. Changing this from a build *error* to a
*warning* is a general improvement if we are unable to delete the
directory. The error code will also be preserved.

I don't know if this will help our users at all, but should help our CI.
@jpobst
Copy link
Contributor

jpobst commented Mar 23, 2020

I agree that we should do this fix, but I think we should also look and see if something changed recently that has caused this to start happening. Presumably something is still holding these files open that previously was not.

@jonathanpeppers
Copy link
Member Author

@jpobst the only thing that would hold these directories open is aapt2.exe, and I don't see that process hanging around:

https://dev.azure.com/DevDiv/DevDiv/_build/results?buildId=3574952&view=logs&j=035e6729-702a-53d4-bea9-761745a9f552&t=c612f891-5417-5f54-1118-32301bb7e92f&l=63

I have no explanation, unless you have an idea.

We haven't changed aapt2, except for this PR that isn't merged yet: #4190

Maybe its PR builds could break other PRs running on the same machine?

@jonathanpeppers
Copy link
Member Author

This PR is nearly green, but we get a network issue:

System.Net.WebException : Error: SecureChannelFailure (Remote prematurely closed connection.)
----> System.IO.IOException : Remote prematurely closed connection.

I'm going to merge, as it seems to help the Windows side.

@jonathanpeppers jonathanpeppers merged commit 7709d60 into dotnet:master Mar 23, 2020
@jonathanpeppers jonathanpeppers deleted the removedirfixed-warnandcontinue branch March 23, 2020 20:43
jonpryor pushed a commit that referenced this pull request Mar 23, 2020
… dirs (#4444)

Context: https://build.azdo.io/3575078
Context: https://build.azdo.io/3574952

Our CI builds have been hitting random failures such as:

    (_UpdateAndroidResgen target) ->
    error XARDF7024: System.IO.IOException: The directory is not empty.
    error XARDF7024:
    error XARDF7024:    at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data)
    error XARDF7024:    at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
    error XARDF7024:    at Xamarin.Android.Tasks.RemoveDirFixed.RunTask()

Or in another target:

    (_CreateBaseApk target) ->
    error XARDF7024: System.IO.IOException: The directory is not empty.
    error XARDF7024:
    error XARDF7024:    at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data)
    error XARDF7024:    at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
    error XARDF7024:    at Xamarin.Android.Tasks.RemoveDirFixed.RunTask()

In both of these places, we have the pattern:

    <CreateTemporaryDirectory>
      <Output TaskParameter="TemporaryDirectory" PropertyName="AaptTemporaryDirectory" />
    </CreateTemporaryDirectory>
    <!-- Then later on -->
    <RemoveDirFixed Directories="$(AaptTemporaryDirectory)" />

The temporary directory is created in C# via:

    TemporaryDirectory = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ());
    Directory.CreateDirectory (TemporaryDirectory);

I think a solution here is to make the `<RemoveDirFixed/>` call set to
`ContinueOnError="WarnAndContinue"`. I don't think we need to *fail*
the overall build in these scenarios.

The user is going to have leftover files in `%TEMP%`, and I don't
think there is much we can do. Changing this from a build *error* to a
*warning* is a general improvement if we are unable to delete the
directory. The error code will also be preserved.

I don't know if this will help our users at all, but should help our CI.
@brendanzagaeski
Copy link
Contributor

Draft release note

Although this issue hasn't been reported by users, I'll plan to include a tiny note for it just to be thorough.

Here's what I'm thinking:

  * [GitHub PR 4444](https://github.com/xamarin/xamarin-android/pull/4444):
    *System.IO.IOException: The directory is not empty* could sometimes prevent
    the `RemoveDirFixed` task from removing temporary build directories.  The
    task now produces a warning instead, allowing the build to complete
    successfully.

To suggest something different or to recommend excluding it from the release notes, feel free to reply in this PR or add a Documentation/release-notes/4444.md file with the new suggestion. Thanks in advance!

@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants