Skip to content

Commit

Permalink
Merge pull request #94 from sergeyzenchenko/asynk-client-mutex-fix
Browse files Browse the repository at this point in the history
Fix Mutex usage in asynk::client::cleanup_subscriptions function.
  • Loading branch information
Stjepan Glavina authored Sep 1, 2020
2 parents 7a73ab7 + 7a40dc1 commit 59a0710
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/asynk/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,10 @@ impl Client {

/// Sends UNSUB for dead subscriptions.
async fn cleanup_subscriptions(&self, state: &mut async_mutex::MutexGuard<'_, State>) {
for sid in mem::replace(&mut *self.unsubscribed.lock().unwrap(), HashSet::new()) {
// Keep unsubscribed list in separate variable so it won't be captured by for loop context.
let unsubscribed = mem::replace(&mut *self.unsubscribed.lock().unwrap(), HashSet::new());

for sid in unsubscribed {
// Remove the subscription from the map.
state.subscriptions.remove(&sid);

Expand Down

0 comments on commit 59a0710

Please sign in to comment.