Skip to content
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

Sonar PRCA: IndexOutOfRangeException #2045

Closed
pascalberger opened this issue Jul 8, 2016 · 15 comments
Closed

Sonar PRCA: IndexOutOfRangeException #2045

pascalberger opened this issue Jul 8, 2016 · 15 comments
Assignees

Comments

@pascalberger
Copy link
Contributor

I've uploaded the Sonar Post task based on this PR (to fix #2044]. With this version I get an IndexOutOfRangeException:

2016-07-08T10:13:02.5044897Z Post-processing succeeded.
2016-07-08T10:13:02.5044897Z Fetching code analysis issues and posting them to the PR...
2016-07-08T10:13:02.8373938Z SonarQube found 102 issues out of which 23 are new
2016-07-08T10:13:02.8951315Z 6 issue(s) do not relate to a specific file and will not be posted to the code review
2016-07-08T10:13:06.2618668Z Processing 17 new messages
2016-07-08T10:13:07.6345493Z 0 message(s) were filtered because they do not belong to files that were changed in this PR
2016-07-08T10:13:07.6657977Z 0 message(s) were filtered because they were already present
2016-07-08T10:13:07.6970505Z 0 message(s) were filtered to match the maximum 100 comments limit
2016-07-08T10:13:08.6423888Z ##[error]System.IndexOutOfRangeException: Index was outside the bounds of the array.
2016-07-08T10:13:08.6423888Z ##[error]   at System.Management.Automation.Adapter.CompareOverloadCandidates(OverloadCandidate candidate1, OverloadCandidate candidate2, Object[] arguments)
2016-07-08T10:13:08.6423888Z ##[error]   at System.Management.Automation.Adapter.FindBestCandidate(IEnumerable`1 candidates, Object[] arguments)
2016-07-08T10:13:08.6580171Z ##[error]   at System.Management.Automation.Adapter.FindBestCandidate(IEnumerable`1 candidates, Object[] arguments, PSMethodInvocationConstraints invocationConstraints)
2016-07-08T10:13:08.6580171Z ##[error]   at System.Management.Automation.Adapter.FindBestMethod(MethodInformation[] methods, PSMethodInvocationConstraints invocationConstraints, Object[] arguments, String& errorId, String& errorMsg, Boolean& expandParamsOnBest)
2016-07-08T10:13:08.6580171Z ##[error]   at System.Management.Automation.Language.PSInvokeMemberBinder.InvokeDotNetMethod(DynamicMetaObject target, DynamicMetaObject[] args, BindingRestrictions restrictions, MethodInformation[] mi, Type errorExceptionType)
2016-07-08T10:13:08.6580171Z ##[error]   at System.Management.Automation.Language.PSInvokeMemberBinder.FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
2016-07-08T10:13:08.6580171Z ##[error]   at System.Dynamic.DynamicMetaObject.BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
2016-07-08T10:13:08.6580171Z ##[error]   at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)
2016-07-08T10:13:08.6580171Z ##[error]   at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
2016-07-08T10:13:08.6580171Z ##[error]   at System.Dynamic.UpdateDelegates.UpdateAndExecute8[T0,T1,T2,T3,T4,T5,T6,T7,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
2016-07-08T10:13:08.6580171Z ##[error]   at System.Management.Automation.Interpreter.DynamicInstruction`9.Run(InterpretedFrame frame)
2016-07-08T10:13:08.6580171Z ##[error]   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2016-07-08T10:13:08.6736395Z Creating a discussion comment for the message at line 29 from /IOZ.Tools.ModelGenerator/IOZ.Tools.ModelGenerator/CodeCommenter.cs
2016-07-08T10:13:08.8455135Z ##[error]System.Management.Automation.RuntimeException: No changes found for /IOZ.Tools.ModelGenerator/IOZ.Tools.ModelGenerator/CodeCommenter.cs ---> System.Management.Automation.RuntimeException: No changes found for /IOZ.Tools.ModelGenerator/IOZ.Tools.ModelGenerator/CodeCommenter.cs
2016-07-08T10:13:08.8455135Z ##[error]   --- End of inner exception stack trace ---
2016-07-08T10:13:08.8455135Z ##[error]   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
2016-07-08T10:13:08.8455135Z ##[error]   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
2016-07-08T10:13:08.8455135Z ##[error]   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
2016-07-08T10:13:08.8455135Z ##[error]   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
2016-07-08T10:13:08.8611493Z ##[error]   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
2016-07-08T10:13:08.8611493Z ##[error]   at Microsoft.TeamFoundation.DistributedTask.Handlers.PowerShellHandler.Execute(ITaskContext context, CancellationToken cancellationToken, Int32 timeoutInMinutes)
2016-07-08T10:13:08.8611493Z ##[error]   at Microsoft.TeamFoundation.DistributedTask.Worker.JobRunner.RunTask(ITaskContext context, TaskWrapper task, CancellationTokenSource tokenSource)
@pascalberger
Copy link
Contributor Author

pascalberger commented Jul 8, 2016

There seems to be two errors while the second error (No changes found) seems to be #1968, but there's an additional IndexOutOfRangeException this time.

@HSAR
Copy link
Contributor

HSAR commented Jul 8, 2016

Hi Pascal, thanks again for reporting your issue. This is really useful - I've been trying to repro this bug since yesterday. Is there any way you can supply the sonar-report.json from this build?

@pascalberger
Copy link
Contributor Author

Sure, you can find it here.

@ericsciple
Copy link
Contributor

@pascalberger - Disclaimer: this is a totally untested hypothesis, I am not familiar with these tasks: one of the REST SDK httpclient calls may be returning an error that isn't bubbling. Instead of calling .Result, you could try modifying the code to call .GetAwaiter().GetResult() instead which will bubble the error. I have seen a similar issue recently, but don't understand why calling .Result from PowerShell doesn't bubble the error.

@HSAR
Copy link
Contributor

HSAR commented Jul 8, 2016

An update in the interest of keeping people informed: I'm still unable to repro this issue due to a (seemingly) unrelated bug in this same task.

However, two seperate customers with different build pipelines encountering the same IndexOutOfRange error does seem to indicate there is a problem with the task code itself, and it is not a configuration problem.

@pascalberger
Copy link
Contributor Author

@ericsciple Updating which tasks? The Sonar Task?

@ericsciple
Copy link
Contributor

Yes, the one erroring during your build. Again, it's only a wild guess that may help to narrow-in on the root of the issue. I happened to notice that task calls .Result when invoking methods on the vsts http clients. My wild guess is: an exception may not be bubbling from .Result and causing the task to later manifest IndexOutOfRange due to an unexpected condition.

@pascalberger
Copy link
Contributor Author

@ericsciple Unfortunately changing .Result to .GetAwaiter().GetResult() in https://github.com/Microsoft/vsts-tasks/blob/master/Tasks/SonarQubePostTest/PRCA/PostComments-Server.ps1 hasn't changed anything. Still the same two error messages.

@pascalberger
Copy link
Contributor Author

Looking at the log output before the IndexOutOfRange Exception:

2016-07-08T10:13:07.6970505Z 0 message(s) were filtered to match the maximum 100 comments limit

And the one immediately after:

2016-07-08T10:13:08.6736395Z Creating a discussion comment for the message at line 29 from /IOZ.Tools.ModelGenerator/IOZ.Tools.ModelGenerator/CodeCommenter.cs

I assume the error occurs somewhere after https://github.com/Microsoft/vsts-tasks/blob/89b14959c6a1dc69a1845dba2cefc8f535144bd4/Tasks/SonarQubePostTest/PRCA/PostComments-Module.psm1#L114 and https://github.com/Microsoft/vsts-tasks/blob/89b14959c6a1dc69a1845dba2cefc8f535144bd4/Tasks/SonarQubePostTest/PRCA/PostComments-Module.psm1#L404 in the CreateDiscussionThreads function.

@pascalberger
Copy link
Contributor Author

pascalberger commented Jul 8, 2016

After further debugging I found that the IndexOutOfRange Exception is thrown by the call to GetChangesAsync here. Therefore the change to use .GetAwaiter().GetResult() instead of .Result didn't had an effect, since the exception was thrown before.

@bgavrilMS
Copy link
Member

Hi Pascal,

I think I know where this exception is being thrown from - it's a PowerShell bug. PowerShell cannot easily distinguish between overloads (because it's not a strongly typed language) so it has complex logic to pick the right overload.

When you repro this - do you use the hosted agent? I'm asking because the hosted agent has Win Server 2012 and that uses PowerShell 4. Win 10 has PowerShell 5, which is probably why can't repro the bug.

@pascalberger
Copy link
Contributor Author

It's an on-prem agent with PowerShell 4

@bgavrilMS
Copy link
Member

Thanks, I am now able to repro the problem. I am preparing a fix.

@pascalberger
Copy link
Contributor Author

Thanks @bgavrilMS! #2057 seem to have fixed this issue.

@bgavrilMS
Copy link
Member

Great, thank you for confirming Pascal! We're going to hotfix this so it will roll out soon.

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

No branches or pull requests

4 participants