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

Add support for accessing headers and trailers to streaming calls #171

Merged
merged 4 commits into from
Dec 8, 2023

Conversation

jhump
Copy link
Member

@jhump jhump commented Dec 7, 2023

This is done via a CompletableDeferred which is completed when the headers/trailers are received.

…red, which completes when the headers or trailers are received
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.

Changes look good to me.

}
}

// TODO: remove this method as it is redundant with receive closed
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems fine to remove the method if it isn't needed. I don't really see any consumers of this anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's referenced indirectly in all three of the stream interfaces and their impls. I figured I'd put that diff churn in a separate PR where I also hope to do some other improvement/overhauling of the stream interfaces.

@@ -76,11 +76,14 @@ class Stream(
fun receiveClose() {
if (!isReceiveClosed.getAndSet(true)) {
onReceiveClose()
// closing receive side implicitly closes send side, too
isSendClosed.set(true)
Copy link
Contributor

@pkwarren pkwarren Dec 7, 2023

Choose a reason for hiding this comment

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

Should we call sendClose() instead here so the onSendClose() callback is always invoked? Do we want to invoke this in a try / finally to ensure it will always be run even if an exception occurs in onReceiveClose?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't want onSendClose() to be invoked because that will try to half-close the stream (which should fail since the thing is already done at this point). And I don't think we want to call sendClose() first (before doing the receive side) because that is just an extra, unnecessary network packet to send the half-close (technically an empty "end-of-stream" data frame) when the cancellation is all that is needed. As the comment says, closing the receive side of the stream implicitly closes the send -- so book-keeping is all that is needed here and no other action. I can add comments to this effect.

Unclear about using try/finally. On the one hand, if onReceiveClose fails, then the stream may not be closed so that's an argument to not use finally. However, it doesn't really make much sense to leave isSendClosed set to false when isReceiveClosed is set to true. So I guess I've talked myself into needing a finally here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to use try/finally and added a comment as to why this isn't calling sendClose().

@jhump jhump marked this pull request as ready for review December 7, 2023 22:10
@jhump
Copy link
Member Author

jhump commented Dec 7, 2023

@pkwarren, I added some assertions to existing test cases related to headers with streaming operations. PTAL

@jhump jhump merged commit 92cc2a7 into main Dec 8, 2023
8 checks passed
@jhump jhump deleted the jh/headers-trailers branch December 8, 2023 01:05
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.

2 participants