Skip to content

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Sep 17, 2021

Fixes #1406

Adds a TaskCompletionSource<HttpResponseMessage> so that the task to get the response is never null.

Best reviewed with hide whitespace enabled.

}

if (CommitedCallTask.IsCompletedSuccessfully() && CommitedCallTask.Result == call)
finally
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed we don't do any except handling on the top-level of the StartCall here. Is it worthwhile to do here or is the exception handling at the call sites sufficient?

Copy link
Member Author

@JamesNK JamesNK Sep 21, 2021

Choose a reason for hiding this comment

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

All logic that can throw should be inside a try/catch.

However, a global catch is a good idea for safety. Also, throwing on CTS cancellation and reusing HandleUnexpectedError simplifies the code.

Updated.

// There is no response task if there was a preemptive cancel.
CompatibilityHelpers.Assert(call.CancellationToken.IsCancellationRequested, "Request should have been made if call is not preemptively cancelled.");
call.CancellationToken.ThrowIfCancellationRequested();
httpResponse = await call.HttpResponseTask.ConfigureAwait(false);
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
httpResponse = await call.HttpResponseTask.ConfigureAwait(false);
httpResponse = await call!.HttpResponseTask.ConfigureAwait(false);

call is guaranteed to be set here, correct? Annotation makes it a little easier to read since it's nullable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, a call is always set at this point.

I think an annotation makes it less clear what is going on. Since this compiles, code analysis guarantes that it's not null here. An annotation would make me wonder why this could be null.

@JamesNK JamesNK merged commit a01ea84 into grpc:master Sep 22, 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.

NullReferenceException with channel interceptor and retry policy

2 participants