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

+str Add onErrorComplete operator. #31639

Merged
merged 1 commit into from
Apr 17, 2023
Merged

Conversation

He-Pin
Copy link
Member

@He-Pin He-Pin commented Sep 30, 2022

#31671

@marcospereira @ncreep Would you like to give some inputs?

Have to duplicate some code, as the ambiguous reference to overloaded definition issue.

Still need to add some tests.

@He-Pin He-Pin marked this pull request as draft September 30, 2022 15:14
@He-Pin He-Pin force-pushed the recoverWithComplete branch 3 times, most recently from 4a0d34e to 82cdeb9 Compare September 30, 2022 19:02
@He-Pin He-Pin marked this pull request as ready for review September 30, 2022 19:12
@He-Pin He-Pin marked this pull request as draft September 30, 2022 19:13
@He-Pin He-Pin marked this pull request as ready for review September 30, 2022 19:47
@ncreep
Copy link

ncreep commented Oct 1, 2022

Hi @He-Pin,

Thanks for the effort, but this feature doesn't really address my original request. One of my requirements is that I didn't want to catch exceptions blindly, but rather avoid throwing them in the first place (as idle-timeout) does.

@He-Pin
Copy link
Member Author

He-Pin commented Oct 2, 2022

I think we can add a akka's timeout exception,which extends the current TimeoutExpection?

@He-Pin
Copy link
Member Author

He-Pin commented Oct 2, 2022

@ncreep I want to compose #31640 with this pr, what do you think about it?

@ncreep
Copy link

ncreep commented Oct 2, 2022

#31640 does resolve my issue with the exception (if you add the recoverWithComplete close enough to the idle component). But I'd rather avoid using exceptions for flow control. Seeing how in my use-case having the timeout is not at all "exceptional", I think it would be nicer to have a non-exceptional way to create completion.

Having said, I think the recoverWithComplete is generally useful, and I don't have any other objections.

@He-Pin
Copy link
Member Author

He-Pin commented Oct 2, 2022

@ncreep Yes, I think the current idleTimeout can accept an alternative Source when idle. if the alternative source is not provided, then just fail the source.
then idleTimeout(timeout, Source.empty) will address your origin issue.

@ncreep
Copy link

ncreep commented Oct 3, 2022

@He-Pin, that does sound good. But I wonder whether there's something more general that can be done here. Some implementation that won't be specific to just the idleTimeout use-case. I guess that thinking about this is what got the original issue side-tracked...

Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

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

I like this, together with #31640 it nicely covers the various timeout scenarios.

I wonder if we should skip the no-param variation though, handing it Throwable in user code seems concise enough for the catch-all IMO.

Also not sure about the name, should it rather be something like completeOn[IdleTimeoutException]? Recover would be to turn the stream back into something working, but this operator always completes.

@He-Pin
Copy link
Member Author

He-Pin commented Oct 3, 2022

Cool, I was following the old name, your completeOn is definitely a better name, the name in reactor-core is onErrorComplete.

@He-Pin
Copy link
Member Author

He-Pin commented Oct 3, 2022

@ncreep I was thinking about that too, but never came out a better idea. Will try to get this merged first:) do you have something in mind?

@He-Pin He-Pin changed the title +str Add recoverWithComplete operator. +str Add completeOn operator. Oct 4, 2022
@He-Pin He-Pin marked this pull request as draft October 4, 2022 17:20
@He-Pin
Copy link
Member Author

He-Pin commented Oct 4, 2022

Still on holiday, will try to find more time to get it ready.

@He-Pin He-Pin force-pushed the recoverWithComplete branch 2 times, most recently from 6278b13 to c935b2c Compare October 5, 2022 02:56
@ncreep
Copy link

ncreep commented Oct 11, 2022

@ncreep I was thinking about that too, but never came out a better idea. Will try to get this merged first:) do you have something in mind?

@He-Pin, no, unfortunately I'm not proficient enough in the underlying mechanics of Akka streams to have something concrete in mind.

But I can imagine that whatever the general solution would be it would have to include some change to the underlying signalling mechanism. So that you can "catch" completion signals and then convert those into exceptions. So on its own, idleTimeout would send a completion signal, and then if you want the current behavior back you wrap that signal and throw a Timeout exception for it. That would require some way to identify the origin of the completion signal, so that you don't accidentally catch signals that you didn't mean to. Though maybe something more local would be better, so that every component would receive an onComplete handler, which can decide what to do with the completion of the underlying component (all this assumes that the direction of complete -> exception is more "natural" than exception -> complete).

I'm probably reinventing the wheel here, so I'll stop babbling...

@He-Pin
Copy link
Member Author

He-Pin commented Oct 14, 2022

@patriknw Any suggestion? I want to allocate one day to continue work on this.

@He-Pin He-Pin force-pushed the recoverWithComplete branch 2 times, most recently from 791345a to 73715c1 Compare November 10, 2022 04:28
@He-Pin He-Pin marked this pull request as ready for review November 10, 2022 05:08
@He-Pin He-Pin force-pushed the recoverWithComplete branch 2 times, most recently from f64674a to e39f338 Compare November 10, 2022 09:26
Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

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

LGTM, lets go with the empty param list like this 👍

@johanandren johanandren added the 2 - pick next Used to mark issues which are next up in the queue to be worked on. The tag is non-binding label Feb 7, 2023
@He-Pin
Copy link
Member Author

He-Pin commented Apr 1, 2023

@patriknw I have rebased on to the current main

@He-Pin He-Pin force-pushed the recoverWithComplete branch 2 times, most recently from 3585715 to ce06a9a Compare April 5, 2023 09:14
akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala Outdated Show resolved Hide resolved
*
* '''Cancels when''' downstream cancels
*/
def completeOn(predicate: java.util.function.Predicate[_ >: Throwable]): javadsl.Source[Out, Mat] =
Copy link
Member

Choose a reason for hiding this comment

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

I know the naming has been discussed, but this name doesn't include much about that it is about errors. Might be difficult to discover. onErrorComplete is better. I still like recoverWithComplete because it's close to what we already have, but seems like @johanandren didn't like it.

Copy link
Member Author

@He-Pin He-Pin Apr 6, 2023

Choose a reason for hiding this comment

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

There are :

  • onErrorComplete(..)
  • onErrorContinue(...)
  • onErrorMap(...)
  • onErrorReturn(...)
  • onErrorResume(...)
  • onErrorStop(...)

in reactor-core. and should we use completeOn , completeWhen, or recoverWithComplete here? naming is always hard.

Copy link
Member Author

Choose a reason for hiding this comment

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

@octonato What's your input? the recoverWithComplete align better but seems like completeWhen is a great name too.

Copy link
Member

@octonato octonato Apr 6, 2023

Choose a reason for hiding this comment

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

I agree that onErrorComplete is better for discoverability and it express much better that the method has the intention to be used in case of an error.

About recoverWithComplete, it is less interesting, I think. Internally, we are 'recovering' with empty Source, but that's an implementation detail.

From a user perspective, I don't think recover makes sense because we are not recovering (and continuing) when an error occurs. We are completing gracefully.

That said, maybe a overloaded onErrorComplete (Predicated and PF) will do the job. Clear intention and discoverable.

Copy link
Member Author

Choose a reason for hiding this comment

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

@johanandren I updated the PR to onErrorComplete and the https://github.com/akka/akka-persistence-r2dbc is using Flux too.

And as we here we only matching on error types, and completeOn/completeWhen is more generic.

Copy link
Member

Choose a reason for hiding this comment

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

Let's go with onErrorComplete

@He-Pin He-Pin changed the title +str Add completeOn operator. +str Add onErrorComplete operator. Apr 8, 2023
Copy link
Member

@octonato octonato left a comment

Choose a reason for hiding this comment

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

LGTM

@johanandren johanandren merged commit 1a80c90 into akka:main Apr 17, 2023
@johanandren johanandren modified the milestone: 2.8.1 Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 - pick next Used to mark issues which are next up in the queue to be worked on. The tag is non-binding t:stream
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants