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

OutputStreamPublisher now handles close on its own. #1732

Merged

Conversation

tomas-langer
Copy link
Member

Signed-off-by: Tomas Langer tomas.langer@oracle.com

This was discovered by Jersey team - when using OutputStreamPublisher, there was an infinite blocking problem with method close.

Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
@tomas-langer tomas-langer added the jax-rs JAX-RS and Jersey related issues label May 6, 2020
@tomas-langer tomas-langer self-assigned this May 6, 2020
@tomas-langer tomas-langer added this to In Progress in Backlog May 6, 2020
Verdent
Verdent previously approved these changes May 6, 2020
Copy link
Member

@Verdent Verdent left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@olotenko olotenko left a comment

Choose a reason for hiding this comment

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

There are still conditions that can cause a hang.

The whole approach to synchronization here needs review.

Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
@tomas-langer
Copy link
Member Author

Fixed the cases identified based on @olotenko input. Created a follow up #1741 to fix related issues (and classes).

@@ -163,6 +195,7 @@ private void complete(Throwable t) {
subscriber.close(sub -> {
synchronized (invocationLock) {
sub.onError(t);
Copy link
Contributor

Choose a reason for hiding this comment

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

Lock doesn't help to prevent rule §1.7 violation, we can remove synchronization logic from publisher and wrap subscriber in io.helidon.common.reactive.SequentialSubscriber

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker for this PR, just noticing

Copy link

Choose a reason for hiding this comment

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

1.7 violation can be seen to not be reachable in this instance.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking about not very probable use-case of request(-1) vs. exception in publish method

Copy link

Choose a reason for hiding this comment

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

You can see subscriber.close ensures completion signals will be signalled once and only once, as long as they always go through complete which calls subscriber.close.

Copy link
Contributor

Choose a reason for hiding this comment

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

Missed that, thanks for clarification

Copy link

Choose a reason for hiding this comment

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

Pro tip: when designing routines with CPS, ensure a continuation is invoked always. (Not necessarily the same continuation for all outcomes, not necessarily immediately, but you've got to design routines with a guarantee that the continuation is invoked always) You want to not call any continuation only in very rare circumstances.

The problem with the current design of SingleSubscriberHolder is that it can omit calling the continuation, and the caller is not told that that is the case. It is the same behaviour as non-termination. The outcome is that signalCloseComplete is not guaranteed to be reachable, and the completionResult.get can wait indefinitely. The (rather long) timeout then only eventually reclaims the thread.

@tomas-langer tomas-langer merged commit 3ae1a78 into helidon-io:master May 7, 2020
Backlog automation moved this from In Progress to Closed May 7, 2020
@tomas-langer tomas-langer deleted the output-stream-publisher branch May 7, 2020 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jax-rs JAX-RS and Jersey related issues P1
Projects
Backlog
  
Closed
Development

Successfully merging this pull request may close these issues.

None yet

4 participants