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

futures migration to 0.3 #946

Closed
wants to merge 141 commits into from

Conversation

drahnr
Copy link
Collaborator

@drahnr drahnr commented Feb 5, 2021

This is mostly a PR to raise awareness that the migration to futures 0.3 is WIP, see paritytech/cachepot#31 for current status and remaining steps.

Now this is a rather big chunk of changes, partially non-atomic changes over multiple commits.

Ref #945

drahnr and others added 30 commits November 12, 2020 14:01
* change (CI): initial CI

* change (CI): initial CI

* change (CI): add clippy and allow failure
PRs labelled `autorebase:opt-in` will be rebased automatically after updates in `master`.
In order to avoid timestamp presence in static lib files,
making them non-deterministic.

rust-lang/cc-rs@555e773
mozilla/sccache#197
Xanewok and others added 4 commits March 16, 2021 13:42
This brings in line with the original implementation that used
`futures_01::future::select_all`, which waited for any of the underlying
futures to be ready - either server completes or we receive an explicit
shutdown signal or we were idle for long enough.
Otherwise the Tokio timer creation panics because there's no Tokio timer
instance running when spawning via `futures::executor::ThreadPool`
* Spawn root compilation task in Tokio context

Since Tokio 0.2, spawning the `tokio::process::Command` must be done in
the Tokio context, so make sure to spawn the compilation root task in
the Tokio runtime that's now available in the `SccacheService`.

This fixes a hang in the `sccache_cargo` integration test.

* Mark ClientToolchains::put_toolchain as synchronous

It seems entirely synchronous, as it doesn't hit any await points and
additionally seems to be trigger-happy with mutex locks in inner calls,
so better be safe and prevent the future reader from thinking that this
function is async-safe.

* Prepare cache stuff to use Tokio as its I/O-bound task pool

* Prepare to prune ThreadPool entirely in favor of Tokio

The reason for that being not to mix the Tokio runtime and the `futures`
executor. While it's reasonable and possible to do so, I believe there's
bigger benefit for now to stick to a single executor.
It would be great if we could keep the code using 'vanilla' `futures`
crate but Tokio support is so baked in (e.g. child process harness) that
it seems that it'd require a lot more change for questionable benefit in
this case.
Doing so may yield another benefit - currently, there seems to be a lot
of disk I/O being done on a dedicated, blocking thread pool. It's possible,
now that we use a single executor, to use Tokio facilities for async I/O
if this proves to be faster when supported properly by the native
environment at some point (e.g. with `io_uring` on Linux).

* Prefer using Tokio runtime for dist. HTTP client

* Prune futures::executor::ThreadPool

* Prefer using Tokio timer again

* Bring expected test output in line with upstream repository

This lets test pass locally on Ubuntu 20.10 with:
gcc (Ubuntu 10.2.0-13ubuntu1) 10.2.0
Ubuntu clang version 11.0.0-2

* Cherry-pick of CI: switch to staging image before CI is green; fix versions output

85286f9

Co-authored-by: Denis P <denis.pisarev@parity.io>
* Fix some types when not using dist-client feature

* Pull required features for Tokio 0.2

This fixes a `--no-default-features` build since other dependencies
incidentally pulled the relevant features themselves.

* Fix compilation when using only azure feature

* Fix compilation when using only dist-server feature
Most notably prefer std::future::Future over futures::Future since the
std variant is here to stay
Let's stick to the upstream version. We seem to only care about starting
and keeping the child server process alive until the end of the
function, prefer the std variant for simplicity and to avoid footguns
such as `Runtime::enter` that we had to use here.
The async `get_dist_status` called `get_status` that was locally
blocking in a freshly created `Runtime`. Instead, use the already
present `Runtime` instead creating it from scratch and mark `get_status`
appropriately as async.
The only reason that's there is because the compiler is too conservative
and treats borrows as alive longer than they actually are (even with
explicit `drop`). Work around that by creating an owned future instead,
returned from the `resolve_proxied_executable`.

It's worth noting that `async_trait` returns a `Pin<Box>`ed future with
the 'async lifetime, where we have &'async self as the method receiver.
Because of this, we manually construct the future ourselves with the
'static lifetime.
@drahnr
Copy link
Collaborator Author

drahnr commented Apr 18, 2021

Superseded by #985

@drahnr drahnr closed this Apr 18, 2021
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.

None yet

6 participants