From patchwork Thu Apr 23 18:04:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D8449: rust-chg: do not terminate tokio runtime until pager exits From: phabricator X-Patchwork-Id: 46220 Message-Id: <1b0bab8884bbe3faefc36315c694f628@localhost.localdomain> To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Thu, 23 Apr 2020 18:04:19 +0000 Herald added a subscriber: mercurial-patches. Closed by commit rHG4b0185841058: rust-chg: do not terminate tokio runtime until pager exits (authored by yuja). This revision was automatically updated to reflect the committed changes. This revision was not accepted when it landed; it landed in state "Needs Review". REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D8449?vs=21126&id=21193 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D8449/new/ REVISION DETAIL https://phab.mercurial-scm.org/D8449 AFFECTED FILES rust/chg/src/main.rs rust/chg/src/uihandler.rs CHANGE DETAILS To: yuja, #hg-reviewers, Alphare Cc: mercurial-patches, mercurial-devel diff --git a/rust/chg/src/uihandler.rs b/rust/chg/src/uihandler.rs --- a/rust/chg/src/uihandler.rs +++ b/rust/chg/src/uihandler.rs @@ -9,7 +9,7 @@ use std::os::unix::process::ExitStatusExt; use std::process::Stdio; use tokio; -use tokio::process::{ChildStdin, Command}; +use tokio::process::{Child, ChildStdin, Command}; use crate::message::CommandSpec; use crate::procutil; @@ -31,11 +31,21 @@ } /// Default cHg implementation to process requests received from server. -pub struct ChgUiHandler {} +pub struct ChgUiHandler { + pager: Option, +} impl ChgUiHandler { pub fn new() -> ChgUiHandler { - ChgUiHandler {} + ChgUiHandler { pager: None } + } + + /// Waits until the pager process exits. + pub async fn wait_pager(&mut self) -> io::Result<()> { + if let Some(p) = self.pager.take() { + p.await?; + } + Ok(()) } } @@ -51,7 +61,7 @@ // otherwise the server won't get SIGPIPE if it does not write // anything. (issue5278) // kill(peerpid, SIGPIPE); - tokio::spawn(async { pager.await }); // just ignore errors + self.pager = Some(pager); Ok(pin) } diff --git a/rust/chg/src/main.rs b/rust/chg/src/main.rs --- a/rust/chg/src/main.rs +++ b/rust/chg/src/main.rs @@ -83,5 +83,6 @@ .run_command_chg(&mut handler, env::args_os().skip(1)) .await?; procutil::restore_signal_handler_once()?; + handler.wait_pager().await?; Ok(code) }