Skip to content

Commit

Permalink
Merge pull request #180 from nats-io/tyler_idempotent_unsub
Browse files Browse the repository at this point in the history
Idempotent UNSUB avoids sending multiple UNSUB messages when subscrip…
  • Loading branch information
spacejam committed May 19, 2021
2 parents 9b97c1a + a459617 commit bdb1a4a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.9.17

## Improvements

- #180 idempotent unsubscription avoids sending
multiple UNSUB messages.

# 0.9.16

## Improvements
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nats"
version = "0.9.16"
version = "0.9.17"
description = "A Rust NATS client"
authors = ["Derek Collison <[email protected]>", "Tyler Neely <[email protected]>", "Stjepan Glavina <[email protected]>"]
edition = "2018"
Expand Down
4 changes: 2 additions & 2 deletions async-nats/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "async-nats"
version = "0.9.16"
version = "0.9.17"
description = "An async Rust NATS client"
authors = ["Derek Collison <[email protected]>", "Tyler Neely <[email protected]>", "Stjepan Glavina <[email protected]>"]
edition = "2018"
Expand All @@ -17,7 +17,7 @@ maintenance = { status = "actively-developed" }

[dependencies]
blocking = "1.0.2"
nats = { path = "..", version = "0.9.16" }
nats = { path = "..", version = "0.9.17" }

[dev-dependencies]
smol = "1.2.5"
Expand Down
10 changes: 9 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,15 @@ impl Client {
let mut read = self.state.read.lock();

// Remove the subscription from the map.
read.subscriptions.remove(&sid);
if read.subscriptions.remove(&sid).is_none() {
// already unsubscribed

// NB see locking protocol for state.write and state.read
drop(read);
drop(write);

return Ok(());
}

// Send an UNSUB message.
if let Some(writer) = write.writer.as_mut() {
Expand Down

0 comments on commit bdb1a4a

Please sign in to comment.