-
Notifications
You must be signed in to change notification settings - Fork 25
Futureをcancelするための補助的なmoduleを追加 frugalos_configで用いる #98
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
base: develop
Are you sure you want to change the base?
Conversation
|
コメント: 既存のcommitで解決するが、新たにこのPRを準備したのはfibers_rpcのServer構造体を触ろうとするとこのstopの意味を相当明確に定めなければならなくなってしまうため(Serverの停止には一般的に設計が幾つかあると思われるため)、futureのレベルの話で止めようと思ったからということがあります。 |
RpcServiceもcancelの必要ありかどうか確認結論からいうと、ある。その理由としては、 frugalos/frugalos_config/src/cluster.rs Lines 175 to 212 in 2171349
確認結果joinでabortするのはこのケース 原因次のエラーメッセージの通り、timerが問題になる: どのtimerかというと、次の #[derive(Debug)]
struct KeepAlive {
future: Timeout,
timeout: Duration,
extend_period: bool,
}この #[derive(Debug)]
pub struct Timeout {
start: time::Instant,
duration: time::Duration,
inner: Option<poll::poller::Timeout>,
}この #[derive(Debug)]
pub struct Timeout {
cancel: Option<CancelTimeout>,
rx: oneshot::Receiver<()>,
}
impl Future for Timeout {
type Item = ();
type Error = RecvError;
fn poll(&mut self) -> futures::Poll<Self::Item, Self::Error> {
let result = self.rx.poll();
if result != Ok(futures::Async::NotReady) {
self.cancel = None;
}
result
}
}この let mut executor = track!(ThreadPoolExecutor::new().map_err(Error::from))?; の 最小の状況確認コード片上の話をまとめたものが次のコード片である: 対応 let rpc_service = RpcServiceBuilder::new()
.logger(logger.clone())
.finish(executor.handle());
let rpc_service_handle = rpc_service.handle();
let (cancelable_rpc_service, mut rpc_service_cancelizer) = Cancelable::new(rpc_service.map_err(Error::from));
|
…rviceをcancelするようにした。
背景
createまたはjoin時にエラーが発生するissue #65 を解決するためのPR
技術的背景
fibersの内部実装に触れるので、興味がない場合は飛ばしてください
frugalos_config::cluster::create関数frugalos/frugalos_config/src/cluster.rs
Lines 120 to 172 in 2171349
に問題があり、この関数を抜けるタイミングで
thread '<unnamed>' panicked at 'Error: Other (cause; Monitor target aborted)が発生する。より具体的に述べるために、以下の部分に注目する:
この関数を抜けるタイミングで、以下の流れが生じる(ことがある):
executorのdrop処理を進行中に、executorの抱える(fibersレベルでの)pollersメンバhttps://github.com/dwango/fibers-rs/blob/f104bfab6bc73cbdf159529f810eacd39fda8f52/src/executor/thread_pool.rs#L48-L55
がdropされる
https://github.com/dwango/fibers-rs/blob/f104bfab6bc73cbdf159529f810eacd39fda8f52/src/net/tcp.rs#L150-L153
Monitor target abortedエラーが生じる。解決策
frugalos/frugalos_config/src/cluster.rs
Lines 157 to 160 in 2171349
この部分の処理以降では
rpc_serverの機能は一切用いないため、ここで呼び出しているrun_fiberが終了するタイミングでrpc_serverをストップさせたい。そのために、
frugalos_configに、与えられたfutureをストップ可能なfutureに変形するためのmoduleを加えた:https://github.com/frugalos/frugalos/blob/9fc3ea66dd9925b79ae72bde2e057361b7aef1e5/frugalos_config/src/cancelable_future.rs
以下のようにcancel可能なfutureにした上で、停止したいタイミングで明示的に停止シグナルを送る: