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

http-utils: cleanup the BeforeFinallyHttpOperator state #3042

Merged

Conversation

bryce-anderson
Copy link
Contributor

@bryce-anderson bryce-anderson commented Aug 13, 2024

Motivation:

The BeforeFinallyHttpOperator has a few shortcomings

  • It doesn't honor the contract of calling the callbacks only once in the case of multiple subscribes.
  • It won't honor a cancel if in the PROCESSING_PAYLOAD state, which has some weird callback lifetime questions.

Modifications:

  • If we receive a cancellation on the Single before the message body has been subscribed, that counts as a cancel. Once the message body is subscribed ownership of the callbacks are fully transferred to it.
  • Only the first body subscribe gets ownership of the callbacks.

@bryce-anderson bryce-anderson changed the title Bl anderson/more before finally http-utils: cleanup the BeforeFinallyOperator state Aug 13, 2024
@bryce-anderson bryce-anderson marked this pull request as ready for review August 15, 2024 01:40
@@ -163,13 +172,20 @@ public void onSuccess(@Nullable final StreamingHttpResponse response) {
sendNullResponse();
} else if (stateUpdater.compareAndSet(this, IDLE, PROCESSING_PAYLOAD)) {
subscriber.onSuccess(response.transformMessageBody(payload ->
payload.liftSync(messageBodySubscriber -> new MessageBodySubscriber(messageBodySubscriber,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We satisfy the callback requirements but we don't proactively drain the message body. Doing so will be hairy. I personally think it should be up to the receiver of the message to properly dispose of it if they no longer want it, or pass it along until something in the pipeline cares.

Opinions welcome.

Copy link
Member

Choose a reason for hiding this comment

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

Why do you think we may need to drain message body here?

Copy link
Contributor Author

@bryce-anderson bryce-anderson Aug 22, 2024

Choose a reason for hiding this comment

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

Sorry, I certainly wasn't clear. I mean we win the race to send it but what happens if we receive a losing cancel call before the response body has been subscribed to: should we try to drain the message body at that point or is it out of our hands? I think the latter.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's out of our hands. For now, we will rely on operators that generate cancel, like the timeout filter, to clean it up

@bryce-anderson bryce-anderson changed the title http-utils: cleanup the BeforeFinallyOperator state http-utils: cleanup the BeforeFinallyHttpOperator state Aug 19, 2024
Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

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

🚢

@@ -163,13 +172,20 @@ public void onSuccess(@Nullable final StreamingHttpResponse response) {
sendNullResponse();
} else if (stateUpdater.compareAndSet(this, IDLE, PROCESSING_PAYLOAD)) {
subscriber.onSuccess(response.transformMessageBody(payload ->
payload.liftSync(messageBodySubscriber -> new MessageBodySubscriber(messageBodySubscriber,
Copy link
Member

Choose a reason for hiding this comment

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

Why do you think we may need to drain message body here?

…/BeforeFinallyHttpOperator.java

Co-authored-by: Idel Pivnitskiy <[email protected]>
@bryce-anderson bryce-anderson merged commit 372f108 into apple:main Aug 22, 2024
11 checks passed
@bryce-anderson bryce-anderson deleted the bl_anderson/MoreBeforeFinally branch August 22, 2024 15:58
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