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

Allow handlers to timeout #4

Merged
merged 2 commits into from
May 11, 2022
Merged

Allow handlers to timeout #4

merged 2 commits into from
May 11, 2022

Conversation

thomaseizinger
Copy link

@thomaseizinger thomaseizinger commented May 4, 2022

TODO:

  • Change Display implementation on Error so that we provide more context on the actor and handler that failed.

Copy link
Member

@bonomat bonomat left a comment

Choose a reason for hiding this comment

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

Minor things, otherwise looks good.

With

The consequence of this is that a timed-out handler returns Disconnected.

you mean we should introduce a different return type?

tests/handler_timeout.rs Outdated Show resolved Hide resolved
src/context.rs Outdated Show resolved Hide resolved
src/context.rs Outdated Show resolved Hide resolved
@thomaseizinger
Copy link
Author

I think we might want to re-evaluate this and move it into the envelope same as we did here: #5

That might also allow us to more easily return a different type when a handler times out!

@thomaseizinger
Copy link
Author

With

The consequence of this is that a timed-out handler returns Disconnected.

you mean we should introduce a different return type?

Yes! IMO when you call .send, you should know whether the actor is down (Disconnected) or the handler timed out (different return value then).

@luckysori
Copy link

I think we might want to re-evaluate this and move it into the envelope same as we did here: #5

That might also allow us to more easily return a different type when a handler times out!

Okay, let's try that! @bonomat. I'm happy to give this a go if we want to give this change priority.

@luckysori luckysori self-assigned this May 9, 2022
This is momentarily superfluous given that we only have one
`Disconnected` variant, but it will make the diff of the next patch
cleaner.
@luckysori luckysori force-pushed the handler-timeout branch 2 times, most recently from ec3f89e to 2ea9273 Compare May 10, 2022 13:44
@luckysori luckysori requested review from bonomat, da-kami and klochowicz and removed request for da-kami and klochowicz May 10, 2022 13:45
src/address.rs Outdated
let timed_out_res = rx_timed_out.poll_unpin(ctx);

match (result_res, timed_out_res) {
(Poll::Ready(Ok(result)), _) => Poll::Ready(Ok(result)),
Copy link
Member

@bonomat bonomat May 10, 2022

Choose a reason for hiding this comment

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

Would it be worth it to write out the seconds futures state instead of _ here?
The way how it is written atm is that the first case will match if you have a result and timeout. Is that what you want?

Copy link

@luckysori luckysori May 11, 2022

Choose a reason for hiding this comment

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

It is intentional that the first match arm corresponds to the result future being ready and whatever the result is of the timeout future. I want to always succeed if we have the result of the first channel, even if the second future failed for whatever reason.

For instance, if the second future reports that the timeout has passed but the result is actually ready, we obviously should ignore the timeout and return the result. The timeout is only there as a mechanism to stop handlers that have been running for too long without success.

In practice it may be impossible to ever have a situation where both futures are Poll::Ready(Ok(_)) since we're using future::select in envelope.rs. What certainly does happen (consistently) is that the timed_out_channel is dropped as soon as the result_channel returns a value. The Drop implementation of the catty channel construct actually causes the channel to produce an Err(Disconnected). So when we match against the catty::Receivers and we have a successful result for the result_channel, we will have an error for the second one. Which is why we must ignore it for this to work anyway.

Copy link
Member

@bonomat bonomat left a comment

Choose a reason for hiding this comment

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

Looks good. Nice work

@luckysori
Copy link

As a last change, I've added the message name to the Error::TimedOut variant, as it was suggested in get10101/itchysats#1954. I tried to also include the actor name, but I was not convinced because I had to contend with MessageChannels not knowing the actor they are sending the message to.

@luckysori luckysori merged commit b59c07f into master May 11, 2022
@luckysori luckysori deleted the handler-timeout branch May 11, 2022 02:18
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