Commit 98b1a5a2 authored by yuan's avatar yuan
Browse files

Move persistent state flush from client to circmgr

parent 13f39ed8
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -1008,20 +1008,6 @@ async fn continually_expire_channels<R: Runtime>(rt: R, chanmgr: Weak<tor_chanmg
    }
}

impl<R: Runtime> Drop for TorClient<R> {
    // TODO: Consider moving this into tor-circmgr after we have more
    // experience with the state system.
    fn drop(&mut self) {
        match self.circmgr.store_persistent_state() {
            Ok(()) => info!("Flushed persistent state at exit."),
            Err(tor_circmgr::Error::State(tor_persist::Error::NoLock)) => {
                debug!("Lock not held; no state to flush.");
            }
            Err(e) => error!("Unable to flush state on client exit: {}", e),
        }
    }
}

#[cfg(test)]
mod test {
    #![allow(clippy::unwrap_used)]
+13 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ use tor_rtcompat::Runtime;
use std::convert::TryInto;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use tracing::{debug, info, warn};
use tracing::{debug, error, info, warn};

pub mod build;
mod config;
@@ -434,6 +434,18 @@ impl<R: Runtime> CircMgr<R> {
    }
}

impl<R: Runtime> Drop for CircMgr<R> {
    fn drop(&mut self) {
        match self.store_persistent_state() {
            Ok(()) => info!("Flushed persistent state at exit."),
            Err(Error::State(tor_persist::Error::NoLock)) => {
                debug!("Lock not held; no state to flush.");
            }
            Err(e) => error!("Unable to flush state on circuit manager drop: {}", e),
        }
    }
}

#[cfg(test)]
mod test {
    #![allow(clippy::unwrap_used)]