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

Denormalize "Code", slight simplification of HTTP interface #224

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

jhump
Copy link
Member

@jhump jhump commented Feb 21, 2024

Sorry that this is kind of a large PR. The main intent was the first bullet, but I tackled some other things that I think are improvements along the way.

  1. This denormalizes the presence of code. It was previously present both on StreamResult.Complete and ResponseMessage, even though it was redundant with the code on any non-null ConnectException.
  2. Removes Code.OK. It is now just an error code. An "OK" result is easily distinguished by the lack of an exception.
  3. The HTTPClientInterface was previously responsible for translating HTTP status -> Code and the HTTPResponse reported back the status in an optional "trace info" field. But translating status to Code should be the responsibility of the protocol implementations, not the HTTP client. (Though it is still up to the HTTP client to classify exceptions that prevent an HTTP response from being received, as these could be client-implementation-specific exception types). So this change promotes the status code out of trace info and into the HTTPResponse.
  4. ProtocolClient.stream used suspendCancellableCoroutine incorrectly. It looks like it was trying to associate the stream with the coroutine, so if the coroutine is cancelled then the stream is closed. But it is only effective while that method is running, which is almost none at all since it immediately returns a result (no suspensions).

There are some other small clean-ups in here, too, like moving some things around to places that (IMO) make more sense.

…olClient.stream

1. This denormalizes the presence of code. It was previously present both on StreamResult.Complete
   and ResponseMessage, even though it was redundant with the code on any non-null ConnectException.
2. Removes Code.OK. It is now just an error code. An "OK" result is easily distinguished by the lack
   of an exception.
3. The HTTPClientInterface was previously responsible for translating HTTP status -> Code and the
   HTTPResponse reported back the status in an optional "trace info" field. But translating status
   to Code should be the responsibility of the protocols, not the HTTP client impl. So simplified
   by promoting the status code out of trace info and into the HTTPResponse.
4. ProtocolClient.stream used suspendCancellableCoroutine incorrectly. It looks like it was
   trying to associate the stream with the coroutine, so if the coroutine is cancelled then the
   stream is closed. But it is only effective *while* that method was running, and it immediately
   returns a result (no suspensions). After rectifying this, the suspend keyword is no longer
   actually needed for any of the stream-creation methods as they are all async already.
@jhump jhump requested a review from pkwarren February 22, 2024 00:46
@jhump jhump changed the title Denormalize "Code", slightly simplification of HTTP interface Denormalize "Code", slight simplification of HTTP interface Feb 22, 2024
Copy link
Contributor

@pkwarren pkwarren left a comment

Choose a reason for hiding this comment

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

Really nice cleanup - I like the removal of the OK code and having to have it on success messages. This brings this implementation into closer parity with connect-go.

@jhump jhump merged commit db3e4da into main Feb 23, 2024
9 checks passed
@jhump jhump deleted the jh/denormalize branch February 23, 2024 14:17
@erawhctim
Copy link
Contributor

@jhump Just an FYI, this bit threw me off for a sec as we're upgrading to 0.5.0. It could be valuable to call this out explicitly in the release notes 🙏

Removes Code.OK. It is now just an error code. An "OK" result is easily distinguished by the lack of an exception.

@jhump
Copy link
Member Author

jhump commented Mar 15, 2024

@erawhctim, sorry about that. It is actually mentioned in the release notes (search for "com.connectrpc.Code"). But I didn't do a good job of calling attention to it, so thanks for bringing this up.

I've just added a paragraph at the top to make it more clear to users examining the release notes. I've also added a small blurb to the specific bullet that corresponds to this pull request.

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.

3 participants