-
Notifications
You must be signed in to change notification settings - Fork 352
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
Clean up dependencies in talpid-openvpn
#5245
Clean up dependencies in talpid-openvpn
#5245
Conversation
DES-285 Rewrite talpid-openvpn to be more async
The current implementation of spawning and monitoring OpenVPN in |
62e999a
to
e66cd2e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 13 of 17 files at r1, 5 of 5 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @MarkusPettersson98)
talpid-openvpn/src/lib.rs
line 814 at r2 (raw file):
impl ProcessHandle for OpenVpnProcHandle { fn wait(&self) -> io::Result<ExitStatus> { let handle = tokio::runtime::Handle::current();
Was it not possible to replace this with an async method? Having this many sync-async boundaries is making things messier.
talpid-openvpn/src/process/openvpn.rs
line 415 at r2 (raw file):
fn kill(&self) -> io::Result<()> { log::warn!("Killing OpenVPN process"); let rt = tokio::runtime::Builder::new_current_thread()
Was it not possible to replace this with an async method? Having this many sync-async boundaries is making things messier.
I'm not sure we even need the StoppableProcess
trait. We're only implementing it on OpenVpnProcHandle
, so we might as well just add async methods to replace these.
e66cd2e
to
ae414bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 16 of 19 files reviewed, all discussions resolved (waiting on @dlon)
talpid-openvpn/src/lib.rs
line 814 at r2 (raw file):
Previously, dlon (David Lönnhager) wrote…
Was it not possible to replace this with an async method? Having this many sync-async boundaries is making things messier.
done
talpid-openvpn/src/process/openvpn.rs
line 415 at r2 (raw file):
Previously, dlon (David Lönnhager) wrote…
Was it not possible to replace this with an async method? Having this many sync-async boundaries is making things messier.
I'm not sure we even need the
StoppableProcess
trait. We're only implementing it onOpenVpnProcHandle
, so we might as well just add async methods to replace these.
done
I didn't touch StoppableProcess
this time, but I did have to convert it to an async
trait.
ae414bd
to
362f020
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @MarkusPettersson98)
talpid-openvpn/src/lib.rs
line 489 at r3 (raw file):
let handle = self.runtime.clone(); handle.spawn(async move {
I'm sure we could make this whole wait
function async. But I'll not increase the scope of this PR. It's already a big improvement. :)
talpid-openvpn/src/process/openvpn.rs
line 441 at r3 (raw file):
async fn has_stopped(&self) -> io::Result<bool> { let exit_status = self.inner.lock().await.try_wait(); match exit_status {
Nit: Ok(exit_status?.is_some())
talpid-openvpn/src/process/stoppable_process.rs
line 51 at r3 (raw file):
return Ok(true); } thread::sleep(POLL_INTERVAL_MS);
Use tokio::time::sleep
. This blocks the runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @MarkusPettersson98)
talpid-openvpn/src/process/stoppable_process.rs
line 51 at r3 (raw file):
Previously, dlon (David Lönnhager) wrote…
Use
tokio::time::sleep
. This blocks the runtime.
I'm tunnel visioning a bit here. Can't we use tokio::time::timeout()
on Child::wait()
instead of polling?
362f020
to
d678aa3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 17 of 19 files reviewed, 1 unresolved discussion (waiting on @dlon)
talpid-openvpn/src/lib.rs
line 489 at r3 (raw file):
Previously, dlon (David Lönnhager) wrote…
I'm sure we could make this whole
wait
function async. But I'll not increase the scope of this PR. It's already a big improvement. :)
It would be nice, the wait
function is overly complicated due to it not being async
. Maybe due for next cleanup 🧹
talpid-openvpn/src/process/openvpn.rs
line 441 at r3 (raw file):
Previously, dlon (David Lönnhager) wrote…
Nit:
Ok(exit_status?.is_some())
done
talpid-openvpn/src/process/stoppable_process.rs
line 51 at r3 (raw file):
Previously, dlon (David Lönnhager) wrote…
I'm tunnel visioning a bit here. Can't we use
tokio::time::timeout()
onChild::wait()
instead of polling?
tokio::time::timeout
did the trick 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r4, all commit messages.
Reviewable status: 18 of 19 files reviewed, 1 unresolved discussion (waiting on @MarkusPettersson98)
talpid-openvpn/src/process/stoppable_process.rs
line 51 at r3 (raw file):
Previously, MarkusPettersson98 (Markus Pettersson) wrote…
tokio::time::timeout
did the trick 👌
I think this won't work. has_stopped
will return immediately. It won't actually wait for the child process to stop. We need to use timeout
on wait
, if possible.
d678aa3
to
15f255f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 16 of 19 files reviewed, 1 unresolved discussion (waiting on @dlon)
talpid-openvpn/src/process/stoppable_process.rs
line 51 at r3 (raw file):
Previously, dlon (David Lönnhager) wrote…
I think this won't work.
has_stopped
will return immediately. It won't actually wait for the child process to stop. We need to usetimeout
onwait
, if possible.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 3 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @MarkusPettersson98)
talpid-openvpn/src/lib.rs
line 812 at r5 (raw file):
impl ProcessHandle for OpenVpnProcHandle { async fn wait(&self) -> io::Result<ExitStatus> { crate::process::stoppable_process::StoppableProcess::wait(self).await
How about just adding a wait()
method on OpenVpnProcHandle
directly and calling that?
15f255f
to
cf1567c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 16 of 20 files reviewed, all discussions resolved (waiting on @dlon)
talpid-openvpn/src/lib.rs
line 812 at r5 (raw file):
Previously, dlon (David Lönnhager) wrote…
How about just adding a
wait()
method onOpenVpnProcHandle
directly and calling that?
done
cf1567c
to
c19be81
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 7 of 7 files at r6, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved
c19be81
to
ec3352d
Compare
ec3352d
to
053fc67
Compare
`std::io::IsTerminal` has been since Rust `1.70`, which allows us to migrate away from `is_terminal::IsTerminal`.
Remove the dependency on `duct` from `talpid-openvpn`, since we can use `tokio` to spawn processes instead.
Prefer to use the `tokio::test` attribute which ships with `tokio` instead of manually creating a runtime for each test which needs it.
053fc67
to
968c1eb
Compare
Some cleanups to dependencies in
talpid-openvpn
. The major one is replacing duct with tokio::process::Command for spawning an OpenVPN process. The minor cleanups makeonce_cell
a proper workspace-dependency and replacing the is_terminal crate with std::io::IsTerminal.This change is