Skip to content

Avoid trying to boost on non-supported platforms#47373

Merged
davidwengier merged 6 commits intodotnet:masterfrom
Therzok:patch-2
Sep 6, 2020
Merged

Avoid trying to boost on non-supported platforms#47373
davidwengier merged 6 commits intodotnet:masterfrom
Therzok:patch-2

Conversation

@Therzok
Copy link
Contributor

@Therzok Therzok commented Sep 2, 2020

On Mono, this throws an exception every time you try to query it, and it is documented that setting PriorityClass can throw, so adapt to that.

StreamJsonRpc.RemoteInvocationException: Success
  at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult] (StreamJsonRpc.RequestId id, System.String targetName, System.Collections.Generic.IReadOnlyList`1[T] arguments, System.Threading.CancellationToken cancellationToken, System.Boolean isParameterObject) [0x00184] in C:\A\_work\164\s\src\StreamJsonRpc\JsonRpc.cs:1350
  at Microsoft.CodeAnalysis.Remote.RemoteEndPoint.InvokeAsync[T] (System.String targetName, System.Collections.Generic.IReadOnlyList`1[T] arguments, System.Threading.CancellationToken cancellationToken) [0x0005c] in /_/src/Workspaces/Remote/Core/RemoteEndPoint.cs:153
RPC server exception:
System.ComponentModel.Win32Exception: Success
     at System.Diagnostics.Process.set_PriorityClass (System.Diagnostics.ProcessPriorityClass value) [0x00049] in <3b74eb7e72ba49d0adf622008aa5cb32>:0
     at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.set_PriorityClass(System.Diagnostics.ProcessPriorityClass)
     at Microsoft.CodeAnalysis.Remote.UserOperationBooster.Boost () [0x00029] in <8b79db78374649648c6dc65f376ad81c>:0
     at Microsoft.CodeAnalysis.Remote.CodeAnalysisService+<>c__DisplayClass33_0.<GetSemanticClassificationsAsync>b__0 () [0x00012] in <8b79db78374649648c6dc65f376ad81c>:0
     at Microsoft.CodeAnalysis.Remote.ServiceBase.RunServiceAsync[T] (System.Func`1[TResult] callAsync, System.Threading.CancellationToken cancellationToken) [0x00085] in <8b79db78374649648c6dc65f376ad81c>:0

@Therzok Therzok requested a review from a team as a code owner September 2, 2020 13:52
On Mono, this throws an exception every time you try to query it, and it is documented that setting PriorityClass can throw, so adapt to that.

```
StreamJsonRpc.RemoteInvocationException: Success
  at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult] (StreamJsonRpc.RequestId id, System.String targetName, System.Collections.Generic.IReadOnlyList`1[T] arguments, System.Threading.CancellationToken cancellationToken, System.Boolean isParameterObject) [0x00184] in C:\A\_work\164\s\src\StreamJsonRpc\JsonRpc.cs:1350
  at Microsoft.CodeAnalysis.Remote.RemoteEndPoint.InvokeAsync[T] (System.String targetName, System.Collections.Generic.IReadOnlyList`1[T] arguments, System.Threading.CancellationToken cancellationToken) [0x0005c] in /_/src/Workspaces/Remote/Core/RemoteEndPoint.cs:153
RPC server exception:
System.ComponentModel.Win32Exception: Success
     at System.Diagnostics.Process.set_PriorityClass (System.Diagnostics.ProcessPriorityClass value) [0x00049] in <3b74eb7e72ba49d0adf622008aa5cb32>:0
     at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.set_PriorityClass(System.Diagnostics.ProcessPriorityClass)
     at Microsoft.CodeAnalysis.Remote.UserOperationBooster.Boost () [0x00029] in <8b79db78374649648c6dc65f376ad81c>:0
     at Microsoft.CodeAnalysis.Remote.CodeAnalysisService+<>c__DisplayClass33_0.<GetSemanticClassificationsAsync>b__0 () [0x00012] in <8b79db78374649648c6dc65f376ad81c>:0
     at Microsoft.CodeAnalysis.Remote.ServiceBase.RunServiceAsync[T] (System.Func`1[TResult] callAsync, System.Threading.CancellationToken cancellationToken) [0x00085] in <8b79db78374649648c6dc65f376ad81c>:0
```
@Therzok
Copy link
Contributor Author

Therzok commented Sep 2, 2020

Updated!

process.PriorityClass = priorityClass;
return true;
}
catch (Exception e) when (e is PlatformNotSupportedException || e is Win32Exception)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
catch (Exception e) when (e is PlatformNotSupportedException || e is Win32Exception)
catch (Exception e) when (e is PlatformNotSupportedException or Win32Exception)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 did not know about this C# feature until now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New for C# 9 👍

process.PriorityClass = priorityClass;
return true;
}
catch (Exception e) when (e is PlatformNotSupportedException || e is Win32Exception)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Win32Exception mean we should never try again? The docs aren't really clear, but it seems like maybe that could be a temporary failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure of all the possible error codes of the underlying implementation, which is why I initially had no latch to disable future calls.

On macOS, Win32Exception is mostly sent due to invalid pid or lack of permissions, which won't change over time.

@Therzok
Copy link
Contributor Author

Therzok commented Sep 5, 2020

Anything else needed?

@davidwengier davidwengier merged commit 3115ff8 into dotnet:master Sep 6, 2020
@ghost ghost added this to the Next milestone Sep 6, 2020
@Therzok Therzok deleted the patch-2 branch September 6, 2020 11:50
@dibarbet dibarbet removed this from the Next milestone Sep 22, 2020
@dibarbet dibarbet added this to the 16.8.P4 milestone Sep 22, 2020
sharwell added a commit to sharwell/roslyn that referenced this pull request Feb 23, 2021
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

Successfully merging this pull request may close these issues.

6 participants