-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Xamarin.Android.Build.Tasks] helpers for AsyncTask + TPL #2881
Merged
jonpryor
merged 1 commit into
dotnet:master
from
jonathanpeppers:aapt2-unhandled-exception
Mar 29, 2019
Merged
[Xamarin.Android.Build.Tasks] helpers for AsyncTask + TPL #2881
jonpryor
merged 1 commit into
dotnet:master
from
jonathanpeppers:aapt2-unhandled-exception
Mar 29, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Aha! the error is:
I think this should also Or maybe there is some usage of |
jonathanpeppers
added a commit
to jonathanpeppers/xamarin-android
that referenced
this pull request
Mar 27, 2019
Context: dotnet#2881 Context: http://build.devdiv.io/2531303 I have noticed a random failure in our MSBuild tests such as: E:\A\_work\1214\s\bin\Release\lib\xamarin.android\xbuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(84,3): One or more errors occurred. at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](TSource[] array, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body) at Xamarin.Android.Tasks.Aapt2Compile.DoExecute() at Xamarin.Android.Tasks.Aapt2Compile.<Execute>b__15_0() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute() [E:\A\_work\1214\s\bin\TestRelease\temp\BuildAMassiveApp\App1\App1.csproj] So an exception during `Parallel.ForEach` isn't logged in a nice way at all with MSBuild... Additionally, the `aapt2 compile` calls before this do not list any errors... So with dotnet#2881, I added `try-catch` to log the inner exception: Unhandled exception: System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.Collections.Generic.List`1.Add(T item) at Xamarin.Android.Tasks.Aapt2Compile.ProcessDirectory(ITaskItem resourceDirectory) That is when I spotted the issue: * Running `Parallel.ForEach` on `ProcessDirectory` * Parallel calls to `archives.Add()`, where `archives` is a `List<ITaskItem>` instance variable in the MSBuild task. The simple fix here is to put a `lock(foo)` around the `.Add()` call. I will improve the error logging in dotnet#2881.
jonpryor
pushed a commit
that referenced
this pull request
Mar 27, 2019
Context: #2881 Context: http://build.devdiv.io/2531303 I have noticed a random failure in our MSBuild tests such as: E:\A\_work\1214\s\bin\Release\lib\xamarin.android\xbuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(84,3): One or more errors occurred. at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](TSource[] array, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body) at Xamarin.Android.Tasks.Aapt2Compile.DoExecute() at Xamarin.Android.Tasks.Aapt2Compile.<Execute>b__15_0() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute() [E:\A\_work\1214\s\bin\TestRelease\temp\BuildAMassiveApp\App1\App1.csproj] An exception during `Parallel.ForEach()` isn't logged in a nice way at all with MSBuild. Additionally, the `aapt2 compile` calls before this do not list any errors. With #2881, I added `try-catch` to log the inner exception, and got: Unhandled exception: System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.Collections.Generic.List`1.Add(T item) at Xamarin.Android.Tasks.Aapt2Compile.ProcessDirectory(ITaskItem resourceDirectory) That is when I spotted the issue: * Running `Parallel.ForEach` on `ProcessDirectory()` * Parallel calls to `archives.Add()`, where `archives` is a `List<ITaskItem>` instance variable in the MSBuild task. The simple fix here is to put a `lock(lockObject)` around the `archives.Add()` call.
d0f0e42
to
9e0404e
Compare
9e0404e
to
c8c3b30
Compare
@monojenkins build |
Unhandled exceptions from a `Parallel.ForEach` log an exception in MSBuild such as: E:\A\_work\1214\s\bin\Release\lib\xamarin.android\xbuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(84,3): One or more errors occurred. at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](TSource[] array, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body) at Xamarin.Android.Tasks.Aapt2Compile.DoExecute() at Xamarin.Android.Tasks.Aapt2Compile.<Execute>b__15_0() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute() [E:\A\_work\1214\s\bin\TestRelease\temp\BuildAMassiveApp\App1\App1.csproj] `One or more errors occurred` is not helpful, and it looks like this could happen in several places throughout our MSBuild tasks. The only way to get a better error is to add a `try-catch` and manually log the exception. A couple extension methods can simplify where we use the PCL, and fix this problem at the same time: * `Parallel.ForEach` -> `this.ParallelForEach()`: * Can setup `ParallelOptions` & `CancellationToken` * Adds a `try-catch` block that reports `XA0000` on unhandled exceptions * Calls `AsyncTask.Cancel()` if there is an exception * `this.ParallelForEachWithLock` passes an `object lockObject` to the inner method for any needed locking. * `Task.Run` -> `this.RunTask()` * Sets up the `CancellationToken` With these extension methods we can also drop this `using` in several files: using ThreadingTasks = System.Threading.Tasks; It is a bit annoying to have to disambiguate an MSBuild task from a threading task.
c8c3b30
to
c4954b8
Compare
dellis1972
approved these changes
Mar 29, 2019
I think all the build failures are OK:
|
jonpryor
pushed a commit
that referenced
this pull request
Apr 3, 2019
Context: #2881 Context: http://build.devdiv.io/2531303 I have noticed a random failure in our MSBuild tests such as: E:\A\_work\1214\s\bin\Release\lib\xamarin.android\xbuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(84,3): One or more errors occurred. at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](TSource[] array, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally) at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body) at Xamarin.Android.Tasks.Aapt2Compile.DoExecute() at Xamarin.Android.Tasks.Aapt2Compile.<Execute>b__15_0() at System.Threading.Tasks.Task.InnerInvoke() at System.Threading.Tasks.Task.Execute() [E:\A\_work\1214\s\bin\TestRelease\temp\BuildAMassiveApp\App1\App1.csproj] An exception during `Parallel.ForEach()` isn't logged in a nice way at all with MSBuild. Additionally, the `aapt2 compile` calls before this do not list any errors. With #2881, I added `try-catch` to log the inner exception, and got: Unhandled exception: System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.Collections.Generic.List`1.Add(T item) at Xamarin.Android.Tasks.Aapt2Compile.ProcessDirectory(ITaskItem resourceDirectory) That is when I spotted the issue: * Running `Parallel.ForEach` on `ProcessDirectory()` * Parallel calls to `archives.Add()`, where `archives` is a `List<ITaskItem>` instance variable in the MSBuild task. The simple fix here is to put a `lock(lockObject)` around the `archives.Add()` call.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Unhandled exceptions from a
Parallel.ForEach
log an exception inMSBuild such as:
One or more errors occurred
is not helpful, and it looks like thiscould happen in several places throughout our MSBuild tasks. The only
way to get a better error is to add a
try-catch
and manually log theexception.
A couple extension methods can simplify where we use the PCL, and fix
this problem at the same time:
Parallel.ForEach
->this.ParallelForEach()
:ParallelOptions
&CancellationToken
try-catch
block that reportsXA0000
on unhandledexceptions
AsyncTask.Cancel()
if there is an exceptionthis.ParallelForEachWithLock
passes anobject lockObject
to theinner method for any needed locking.
Task.Run
->this.RunTask()
CancellationToken
With these extension methods we can also drop this
using
in severalfiles:
It is a bit annoying to have to disambiguate an MSBuild task from a
threading task.