diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index cffc43e..61a5401 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -1336,9 +1336,7 @@ impl Session { } pub async fn pause(&self, handle: &ManagedTorrentHandle) -> anyhow::Result<()> { - handle - .pause() - .map(|_| handle.locked.write().paused = true)?; + handle.pause()?; self.try_update_persistence_metadata(handle).await; Ok(()) } diff --git a/crates/librqbit/src/torrent_state/mod.rs b/crates/librqbit/src/torrent_state/mod.rs index 87ba127..93d2a2b 100644 --- a/crates/librqbit/src/torrent_state/mod.rs +++ b/crates/librqbit/src/torrent_state/mod.rs @@ -274,6 +274,8 @@ impl ManagedTorrent { g.state = ManagedTorrentState::Error(error) } + /// peer_rx: the peer stream. If start_paused=false, must be set. + /// start_paused: if set, the torrent will initialize (check file integrity), but will not start pub(crate) fn start( self: &Arc, peer_rx: Option, @@ -389,6 +391,10 @@ impl ManagedTorrent { } } + if !start_paused && peer_rx.is_none() { + bail!("logic bug: start(start_paused=true, peer_rx=None) called. peer_rx must be set if starting the torrent") + } + let session = self .shared .session @@ -419,6 +425,7 @@ impl ManagedTorrent { ManagedTorrentState::Live(live) => { let paused = live.pause()?; g.state = ManagedTorrentState::Paused(paused); + g.paused = true; self.state_change_notify.notify_waiters(); Ok(()) }