fix: cleanup also the Pending related subs
earlier commit already included cleanup for the Ready and Cancelled cases and this will do the same for Pending cases. the end result doesn't change but as is apparent from the test changes: a single Some(0) becomes None. however this does remove leaking and potential bugs when a previously completed subscription would be reused.
This commit is contained in:
parent
19f79dd690
commit
7b71137eb8
@ -369,13 +369,20 @@ impl<TRes: Debug + PartialEq> Drop for SubscriptionFuture<TRes> {
|
||||
// check if this is the last subscription to this resource
|
||||
let is_last = related_subs.is_empty();
|
||||
|
||||
if is_last {
|
||||
subscriptions.remove(&self.kind);
|
||||
}
|
||||
|
||||
(sub, is_last)
|
||||
});
|
||||
|
||||
if let Some(sub) = sub {
|
||||
// don't bother updating anything that isn't `Pending`
|
||||
if let mut sub @ Subscription::Pending { .. } = sub {
|
||||
debug!("It was the last related subscription, sending a cancel notification");
|
||||
debug!(
|
||||
"Last related subscription dropped, sending a cancel notification for {} to {}",
|
||||
self.id, self.kind
|
||||
);
|
||||
sub.cancel(self.kind.clone(), is_last);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,8 @@ async fn check_cid_subscriptions(ipfs: &Node, cid: &Cid, expected_count: usize)
|
||||
assert_eq!(subs.len(), 1);
|
||||
}
|
||||
let subscription_count = subs.get(&cid.clone().into()).map(|l| l.len());
|
||||
assert_eq!(subscription_count, Some(expected_count));
|
||||
// treat None as 0
|
||||
assert_eq!(subscription_count.unwrap_or(0), expected_count);
|
||||
}
|
||||
|
||||
/// Check if canceling a Cid affects the wantlist.
|
||||
|
Loading…
Reference in New Issue
Block a user