Stream: t-cargo/PubGrub

Topic: How to add a timeout?


view this post on Zulip Eh2406 (Oct 09 2020 at 20:27):

Dependency resolution is NP-Hard. So if we fuzz enough we will find cases that take a long time. If we find one it is interesting to look at it and figure out how it escaped our optimizations. In Cargo when there are debug assertions we have a hard cutoff, a time out where test fail. https://github.com/rust-lang/cargo/issues/6258 is the issue track the propcases found this way.

A users of our crate may want to have a time out. For example a website that lets you see all the transitive deps of a cargo.toml, is opening itself up to a denial of services if there is an input that takes a while.

So for testing I want to add a way to have a timeout, but it may as well be an unobtrusive part of the api, suggestions?

view this post on Zulip Eh2406 (Oct 09 2020 at 20:56):

My thought is made DependencyProvider has an optional method fn callback(&self) -> Result<(), Erorr> {Ok(())} that we call as part of the main loop. If it is overwritten and returns an Err then resolution will fail with that Err. That lets our tests (or a website) add a timeout, and a CLI add an interrupt. But I am open to other suggestions.

view this post on Zulip Matthieu Pizenberg (Oct 09 2020 at 21:22):

Having a dedicated callback seems like a good idea

view this post on Zulip Matthieu Pizenberg (Oct 10 2020 at 00:25):

I just realize I forgot the rest of what I wanted to say above. I added "dedicated" not in opposition to optional, optional is a good idea, but in opposition to hijacking list_available_versions and get_dependencies which can also return errors.

view this post on Zulip Eh2406 (Oct 11 2020 at 02:59):

I'm wondering if callback should take an argument of a struct that has some stats of how much work the resolver has done. For now it can provide no info, but then we can add stuff in the future without breaking the api.

view this post on Zulip Alex Tokarev (Oct 14 2020 at 14:51):

Let's bikeshed the naming I guess. Current suggestions:

view this post on Zulip Alex Tokarev (Oct 14 2020 at 14:52):

I think something like should_cancel/should_interrupt reads well with error handling question mark that follows :laughing:

view this post on Zulip Eh2406 (Oct 14 2020 at 14:53):

I'm feeling should_cancel at the moment.


Last updated: Oct 21 2021 at 21:32 UTC