Skip to content

Conversation

@tmat
Copy link
Member

@tmat tmat commented Jun 9, 2022

No description provided.

@tmat tmat requested review from a team as code owners June 9, 2022 02:38
@ghost ghost added the Area-IDE label Jun 9, 2022
{
// When a connection is dropped we can see ObjectDisposedException even though CancelLocallyInvokedMethodsWhenConnectionIsClosed is set.
// That's because there might be a delay between the JsonRpc detecting the disconnect and the call attempting to send a message.
// Catch the ConnectionLostException exception here and convert it to OperationCanceledException.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Catch the ConnectionLostException exception here and convert it to OperationCanceledException.
// Catch the ObjectDisposedException exception here and convert it to OperationCanceledException.

public static bool ReportAndPropagateUnlessCanceled(Exception exception, CancellationToken contextCancellationToken, ErrorSeverity severity = ErrorSeverity.Uncategorized)
{
if (ExceptionUtilities.IsCurrentOperationBeingCancelled(exception, contextCancellationToken))
if (ExceptionUtilities.IsCurrentOperationBeingCancelled(exception, contextCancellationToken) || exception is OperationCanceledNotMachingCancellationTokenException)
Copy link
Member

Choose a reason for hiding this comment

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

Why not just put this check in IsCurrentOperationBeingCancelled?

Also, instead of a custom exception type, would it be easier to have an overload of IsCurrentOperationBeingCancelled that doesn't take a cancellation token at all, so the caller can decide whether they care about the tokens matching, without having to alter other places to throw a custom exception?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, instead of a custom exception type, would it be easier to have an overload of IsCurrentOperationBeingCancelled that doesn't take a cancellation token at all, so the caller can decide whether they care about the tokens matching

Roslyn doesn't check for matching cancellation tokens.

Copy link
Member Author

Choose a reason for hiding this comment

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

By matching I mean OperationCanceledException is thrown even when the cancellation token that flows into method is not signaled. Clearly Roslyn is checking that, this method does. If the call ends up calling back from OOP to devenv we would report NFE for that exception.

Copy link
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

Roslyn doesn't check for matching cancellation tokens (by design)

@sharwell
Copy link
Contributor

sharwell commented Jun 9, 2022

@tmat I believe with #61787 this change is no longer needed

@tmat
Copy link
Member Author

tmat commented Jun 9, 2022

@tmat I believe with #61787 this change is no longer needed

It is still needed as JSON RPC may throw exceptions such as ObjectDisposedException and ConnectionLostExceptions that callers do not expect.

@sharwell
Copy link
Contributor

sharwell commented Jun 9, 2022

ObjectDisposedException

Can you link to the bucket showing this?

ConnectionLostException

I thought this one was already prevented. Is something showing an unhandled case?

@tmat
Copy link
Member Author

tmat commented Jun 9, 2022

I thought this one was already prevented. Is something showing an unhandled case?

It was already prevented - we just used plain OperationCancelledException instead of a specialized one. The change there is only to use the subtype to avoid NFEs reported from ReportAndPropagateUnlessCanceled that takes cancellation token.

Can you link to the bucket showing this?

I can't. I saw the exception being thrown while debugging the scenarios locally.

@sharwell
Copy link
Contributor

sharwell commented Jun 9, 2022

The change there is only to use the subtype to avoid NFEs reported from ReportAndPropagateUnlessCanceled that takes cancellation token.

This is the part that definitely looks covered by #61787. I particularly like that approach because it resolves the over-bucketing issue without completely blocking access to data about unexpected errors.

@tmat
Copy link
Member Author

tmat commented Jun 9, 2022

Won't we start reporting ConnectionLostExceptions (that are wrapped in OperationCanceledException) if #61787 is merged? These are expected exceptions that occur on shutdown.

Copy link
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

Reviewed with @tmat and we believe this only suppresses reporting of OperationCanceledException from ServiceHub in the specific case where it's caused by the communication pipes shutting down. Would like to see a better name for the exception if at all possible.

@tmat tmat merged commit 68b5bc7 into dotnet:main Jun 16, 2022
@tmat tmat deleted the OOPShutdown branch June 16, 2022 00:54
@ghost ghost added this to the Next milestone Jun 16, 2022
@RikkiGibson RikkiGibson modified the milestones: Next, 17.3 P3 Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants